jquery Add and remove element class attribute instance code: The class property of the element is generally used to set the style, so adding or deleting means changing the style of the element, and here's how to use jquery to delete and add the class attribute value of the element, hoping to help you a bit.
The code example is as follows:
function Switchteachcontrol () { var target=$ ("#thediv"); if (Target.hasclass ("Controloff")) { Target.removeclass ("Controloff"); Target.addclass ("Controlon"); } Else { target.removeclass ("Controlon"); Target.addclass ("Controloff");
This is a function, this function can detect whether an element exists a specified class property value, and then to add or delete the corresponding operation, here is not more introduced, in particular, can refer to the relevant reading.
Related reading:
1.thehasclass () function can be found in the Hasclass () method section of jquery
The 2.removeClass () function can be found in the Removeclass () method section of jquery .
The 3.addClass () function can be found in the AddClass () method section of jquery .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9485
For more information, refer to: http://www.softwhy.com/jquery/
jquery Add and remove elements Class attribute instance code