Cross Platform ClassList (cp-classlist)
Cross Platform ClassList is a cross platform library (IE8+) used for manipulating the classlist of a DOM element.
Installation
Use the package manager [npm] to install cp-classlist.
npm install cp-classlist
Usage
var cpClassList = ; var element = document; // Or you can use querySelector var list = ; //Methods //GET CLASS LISTS list; // returns an array of class names of the element. //ADD CLASS LISTSlist; //Adds classes passed and returns the object. //REMOVE CLASS LISTSlist; //Removes classes passed and returns the object. //TOGGLE CLASS LISTSlist; // Toggles between the class name passed and returns the object. //ITEM IN CLASS LISTlist; // Returns the className of the index passed else false; Note: It throws error when number is not passed //CONTAINSlist; // Returns true if the className is found else false //REPLACE CLASSNAMElist; // If old className is found it replaces it with the new className and returns the object else it returns false //Methods that can be chained //EXAMPLE list //NOTE THAT WHEN replace() 's oldClassName is found and gets Replaced it returns an object which can be chained with other methods
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.