Created
July 18, 2018 18:20
-
-
Save EvanAgee/350b5072e1ec3d82d34cc6a735914eff to your computer and use it in GitHub Desktop.
IE11 add/remove/contains class for SVG
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
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); | |
} | |
} | |
}; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I saw that but don't get how to implement in the original gist