repetitive.classes
Standalone classes() function as a UMD module from the repetitive.js library. Takes any DOM element/s and returns an object allowing you use methods on them, such as: adding, removing, toggling and checking if the element contains specified classes. It's like classList API but better and more browser compatible.
Installation
The package is only 923 bytes minified.
You can install this package from npm:
npm install repetitive.classesnpm install --save repetitive.classesnpm install --save-dev repetitive.classes
Use in a browser:
Documentation
Click here for full documentation page
Pick any DOM element or elements to manipulate its class/es. repetitive.classes will iterate over everything for you.
;;;
You have 4 methods to use: add, remove, toggle and contains:
var el = document; ; // adds these three classes to all button elements ; // removes these three classes from all button elements if they have them ; // removes btn-blue and btn-gray class if the element has one, adds it if it doesn't ; // returns true if all buttons have these two classes, otherwise returns false
You can also chain methods(except for contains()) for better performance:
;
Also, for clarification - this:
after this:
;
will look like this:
Is there something wrong?
Please tell me!