classList.js is a cross-browser JavaScript shim that provides the standard element.classList interface where it is missing or incomplete. It lets developers manipulate CSS class names through a token-based API instead of manually editing className strings. The implementation includes methods for adding, removing, checking, toggling, replacing, and retrieving individual class tokens. It also normalizes partial native implementations that accept only one token or lack the forced-state argument for toggle. The script works in nearly all historical browsers except Internet Explorer 7 and earlier. Its small standalone and minified builds make it suitable for legacy sites that need consistent DOM class handling without a framework.
Features
- CSS class addition and removal
- Class token presence checks
- Optional-state class toggling
- Class token replacement
- Multiple-token method support
- Normalization of incomplete native implementations