title: indexOf match variable in this particular case
body: <p>I want to check if <code>mydiv</code> have or don't have a <em>class</em>, if it don't have it, add whatever it is inside the <em>var</em> <code>newClass</code>. I am attempting to do it like this, but it is not working:</p>
  
  <pre><code>var newClass="classToBeAdded";
  
  if(document.getElementById("mydiv").className.indexOf(/(?:^| )(newClass)(?:$| )/)==-1){
      document.getElementById("mydiv").className+=" "+newClass;
  }
  </code></pre>