Created
December 31, 2015 08:13
-
-
Save elmahdim/f270f91bf59fd7f37e23 to your computer and use it in GitHub Desktop.
vanilla javascript removeClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element.prototype.rmClass = function (className) { | |
var classString = this.className; | |
var classNameIndex = classString.indexOf(className); | |
if (className) { | |
classString = classString.replace(' ' + className, ''); | |
classString = classString.replace(className, ''); | |
} | |
this.className = classString; | |
}; | |
/* @usage */ | |
document.body.rmClass('red'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment