Skip to content

Instantly share code, notes, and snippets.

@Huskie
Created January 23, 2014 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Huskie/8581971 to your computer and use it in GitHub Desktop.
Save Huskie/8581971 to your computer and use it in GitHub Desktop.
Plain JavaScript removeClass function. Relies on hasClass function defined in separate Gist
function removeClass(element, className) {
var newClass = ' ' + element.className.replace( /[\t\r\n]/g, ' ') + ' ';
if(hasClass(element, className)) {
while(newClass.indexOf(' ' + className + ' ') >= 0) {
newClass = newClass.replace(' ' + className + ' ', ' ');
}
element.className = newClass.replace(/^\s+|\s+$/g, '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment