This article brings you the content is about HTML5 new properties: The use of classlist attributes, there is a certain reference value, a friend can refer to the need, I hope you have some help.
The Classlist attribute is added to the HTML5 to implement the class operation with the following API:
Contains (value): Determines whether the class name named value exists Add (value): Add a class name named value Remove (value): Removes the class name named value Toggle (value): If the name value exists , does not exist add
JS Sample code:
Get the node var $test = document.getElementById ("test");//Add a Class$test.classlist.add ("New-class");//Delete a class$ Test.classList.remove ("Old-class");//existence is deleted, does not exist add $test.classlist.toggle ("class");//Determine if it contains $ Test.classList.contains ("class");//Replace Class$test.classlist.remove ("Old-class"); $test. Classlist.add ("New-class") ;