Reference page:
Http://www.w3school.com.cn/jquery/jquery_ref_attributes.asp
1:addclass () Romoveclass (): Adds the specified class name to the matching element one or more, lethal horizon one or more class attributes: (if you add more than one class, you can separate the class name with a space)
A: To add a class to the first P element:$ ("P:first"). AddClass ("Intro");
B: Adding a class using a function
<script type="Text/javascript">
$ (document). Ready (function () {
$("Button"). Click (function () {
$('P'). addclass (function (n) {
return'Par_'+ N;
});
});
});
</script>
<style type="Text/css">
. par_0
{
Color:blue;
}
. par_1
{
color:red;
}
</style>
C : to in the selected element Add two classes: Multiple classes are separated by spaces to :
$ ("P:first"). AddClass ("intro note");
D: to change the class of an element: use AddClass () and Removeclass () to remove the class and add a new class.
$ ("P:first"). Removeclass ("Intro"). AddClass (' main ');
2:hasclass ():checks whether the selected element contains the specified class containing the return true: does not contain return false
Alert ($ ("P:first"). hasClass("intro")
);
3:toggleclass () : Toggles one or more classes that set or remove the selected element : Multiple switches possible
$ ("P"). toggleClass("main")
;
jquery attribute Operation AddClass removeclass hasclass Toggleclass ()