jquery's Toggleclass () function code instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.