jquery remplacer la pas de remplacer tous les espaces avec -

Pourquoi mon jquery ne pas remplacer tous les espaces par un '-'. Il ne remplace la première place avec un '-'

$('.modhForm').submit(function(event) {

        var $this = $(this),
            action = $this.attr('action'),
            query = $this.find('.topsearchbar').val(); //Use val() instead of attr('value').

        if (action.length >= 2 && query.length >= 2 && query.lenght <=24) {

          //Use URI encoding
          var newAction = (action + '/' + query.replace(' ','-'));
          console.log('OK', newAction); //DEBUG

          //Change action attribute
          $this.attr('action', newAction);

        } else {
          console.log('To small to be any good'); //DEBUG

          //Do not submit the form
          event.preventDefault();
        }
    });
InformationsquelleAutor Norman | 2013-01-02