Simplest JS function to add/remove custom classname with carrying about another classes.
just to remember.
function toggleClassName(obj,sClassName,switcher){ if(switcher){ if(obj.className.indexOf(sClassName)==-1) obj.className=obj.className + ' ' + sClassName; }else{ var re = new RegExp(sClassName,'g'); obj.className=obj.className.replace(re,''); } }
australian online casino guidesapienti sat
toggleClassName(div, ‘test’, false)
Oooops…
function toggleClassName(obj,sClassName,switcher){
var re = new RegExp('\b'+sClassName+'\b','g');
if(switcher){
if(!obj.className.match(re))
obj.className=obj.className + ' ' + sClassName;
}else{
obj.className=obj.className.replace(re,'');
}
}
Good idea, thanks a lot! 🙂