title: issue with replace() method in javascript when replacing spaces
body: <p>This is the function I am working with:</p>
  
  <pre><code>function replaceH1s() {
    $("h1").each(function(){
      h1name = $(this).text();
      stuff = h1name.toLowerCase().replace(' ','-');
      $(this).html('&lt;img src="/assets/image/h1_' + stuff + '.png" alt="' + h1name + '" /&gt;');
    })
  }
  </code></pre>
  
  <p>I can't figure out for the life of me why this function replaces the first space in h1name string with a hyphen, but not any of the subsequent ones. I tried unescaping and escaping (and then replacing %20 it stumbles upon with hyphens, but that did the same thing). I tried regular expressions for catchall whitespace and that did the same thing. I feel like I am not seeing something super fundamental here.</p>