I have the next 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 > -1)
{
element.className = replace;
return true;
}
return false;
}
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?
Thank you in advance!
How it’s done on Mozilla hack site: