1. Traditional methods:
When you manipulate the class name, you need to add, remove, and replace the class name with the ClassName property. As in the following example:
<div class= "BD user disabled" >...</div>
This div has a total of three class names, in order to delete a class name, you need to separate the three classes, and then processed, the process is as follows:
<script type= "Text/javascript" > var classname=div.classname.split (/\s+/); Find the class name to delete var pos=-1, I,len; for (var i = 0; i < classname.length; i++) { if (classname[i]== "user") { pos=i; break; } }; Classname.splice (i,1); Div.classname=classname.join ("");//re-assemble the remaining class names </script>
The above-mentioned aspects are traditional methods.
2, HTML5 new Method Classlist (), you can completely get rid of classname properties.
Specific use cases are as follows:
<! DOCTYPE html>
Note: However, the current classlist attribute is supported only by firefox3.6+ and Chrome.
JavaScript Advanced Programming---classlist properties