Skip to content

Instantly share code, notes, and snippets.

@EvanAgee
Created July 18, 2018 18:20
Show Gist options
  • Save EvanAgee/350b5072e1ec3d82d34cc6a735914eff to your computer and use it in GitHub Desktop.
Save EvanAgee/350b5072e1ec3d82d34cc6a735914eff to your computer and use it in GitHub Desktop.
IE11 add/remove/contains class for SVG
if (!("classList" in SVGElement.prototype)) {
Object.defineProperty(SVGElement.prototype, "classList", {
get() {
return {
contains: className => {
return this.className.baseVal.split(" ").indexOf(className) !== -1;
},
add: className => {
return this.setAttribute('class', this.getAttribute('class') + ' ' + className);
},
remove: className => {
var removedClass = this.getAttribute('class').replace(new RegExp('(\\s|^)' + className + '(\\s|$)', 'g'), '$2');
if (this.classList.contains(className)) {
this.setAttribute('class', removedClass);
}
}
};
}
});
}
@dangelion
Copy link

I saw that but don't get how to implement in the original gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment