title: Remove classname from element with javascript
body: <p>I found the following regex from another Stack Overflow question: <a href="https://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript">Change an element&#39;s class with JavaScript</a></p>
  
  <p>And have used it in part of my script with success, however in another it seems to be failing.</p>
  
  <p>I threw together a very minimalist test case on jsFiddle, and it is also failing:</p>
  
  <p><a href="http://jsfiddle.net/ew47Y/1/" rel="noreferrer">http://jsfiddle.net/ew47Y/1/</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div class="foo" id="foo"&gt;
      hello
  &lt;/div&gt;​
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>$(document).ready(function(){
       foo = document.getElementById('foo');
       foo.className += ' bar foobar';
       alert(foo.className);
       foo.className.replace( /(?:^|\s)bar(?!\S)/ , '' )
       alert(foo.className);
  })​
  </code></pre>