title: jquery replace not replacing all spaces with -
body: <p>Why is my jquery not replacing all spaces with a <code>'-'</code>. It only replaces the first space with a <code>'-'</code></p>
  
  <pre><code>$('.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 &gt;= 2 &amp;&amp; query.length &gt;= 2 &amp;&amp; query.lenght &lt;=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();
          }
      });
  </code></pre>