Skip to content

Instantly share code, notes, and snippets.

@DigitalKrony
Created November 27, 2018 15:31
Show Gist options
  • Save DigitalKrony/e204e159e95330ec235ce5e83e8c11f8 to your computer and use it in GitHub Desktop.
Save DigitalKrony/e204e159e95330ec235ce5e83e8c11f8 to your computer and use it in GitHub Desktop.
It removes a class via javascript via Object prototype.
Object.prototype.removeClass = function (string) {
var classList = this.className.split(' ');
var classesToRemove = string.split(' ');
for (var toRemove of classesToRemove) {
var index = classList.indexOf(toRemove);
if(index !== -1) {
classList.splice(index, 1);
}
}
this.classList = classList.join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment