Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Created May 7, 2014 13:57
Show Gist options
  • Save ourmaninamsterdam/b2bda53a5b1ecbb2133c to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/b2bda53a5b1ecbb2133c to your computer and use it in GitHub Desktop.
Libary-less addClass and removeClass functions
function addClass(elem, newClass) {
var curClass = elem.className;
if(!new RegExp(newClass,'i').test(curClass)){
if(curClass.length > 0 && curClass.charAt(curClass.length) === '') {
newClass = ' ' + newClass;
}
elem.className += newClass;
}
};
function removeClass(elem, cssClass) {
elem.className = elem.className.replace(' ' + cssClass,'');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment