jquery's Toggleclass () function code example:
This section demonstrates the use of the Toggleclass () function using a code example, which can determine whether an element has a specified style class, if there is a deletion, and if not, this feature is useful in some switching effects, as shown in the code example:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><styletype= "Text/css">. BG{background:#f00;Color:#fff;width:300px; }ul, Li{List-style:None;font-size:12px;Height:20px;Line-height:20px;}[/size][size=2]ul{padding:0;margin:0;} </style><Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script><Scripttype= "Text/javascript"> $(function(){ $("Li"). MouseOver (SetColor). Mouseout (SetColor); functionSetColor () {$ ( This). Toggleclass ("BG"); } }); </Script></Head><Body><DivID= "Div"> <ul> <Li>Ant Tribe welcomes You</Li> <Li>Only hard struggle will have a good tomorrow</Li> <Li>Every day is a new one to cherish</Li> <Li>Tomorrow is unreal, only the present is real</Li> <Li>Sharing mutual assistance is the greatest source of progress</Li> </ul></Div></Body></HTML>
The above code can implement mouse hover and leave the background color of the LI element to switch effects.
$ ("Li"). MouseOver (SetColor). Mouseout (SetColor), registering an event handler, which of course uses chained calls.
Related reading:
The 1.mouseover event can be found in the MouseOver event section of jquery .
The 2.mouseout event can be found in the Mouseout event section of jquery .
3.toggleClass () refer to the Toggleclass () method section of jquery .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=13108
For more information, refer to: http://www.softwhy.com/jquery/
jquery's Toggleclass () function code instance