DOMTokenList polyfill for IE < 9; implements element.classList
✓ Published0🌍 Public
Aalessioalex
Last edited Oct 30, 2015
Created on Oct 22, 2021
This example shows a JavaScript polyfill that implements the DOMTokenList API to support the `element.classList` property in Internet Explorer 9 and earlier. The code defines the standard methods `add`, `remove`, `toggle`, `contains`, and `item`, and it also patches native implementations in IE 10/11 and Firefox to accept multiple arguments. It stores class lists internally and updates the element’s `className` attribute or SVG `class` attribute when changes occur. The polyfill uses plain DOM methods like `setAttribute` and array operations such as `splice` and `indexOf`.
AI-generated description