title: Optimizing a javascript function with a fallback if classList is not supported
body: <p>I have the next code:</p>
  
  <pre><code>dom.remove_class = function(element, class_name)
  {
      // For Chrome, Firefox...
      if (element.classList)
      {
          return element.classList.remove(class_name);
      }
  
      // Fallback
      var replace = (" " + element.className + " ").replace(/[\n\t\r]/g, " ").replace(" " + class_name + " ", "");
  
      if(replace &gt; -1)
      {
          element.className = replace;
  
          return true;
      }
  
      return false;
  }
  </code></pre>
  
  <p>It easy to return the element.classList.remove() for browsers that support it but the only way I found (inspired by jQuery) on how to return true or false is the fallback part. Anyone knows how I can improve this code? Or it's right like is right now?</p>
  
  <p>Thank you in advance!</p>