JQuery enables multiple buttons to change color. jquery click to change color.

Source: Internet
Author: User

JQuery enables multiple buttons to change color. jquery click to change color.

The code for this small special effect is very simple, so we will not explain it much, but directly provide the source code.

JQuery code:

Copy codeThe Code is as follows:
<Script type = "text/javascript">
// Load the event
$ (Function (){
Var collection = $ (". flag ");
$. Each (collection, function (){
$ (This). addClass ("start ");
});
});
// Click the event
Function dj (dom ){
Var collection = $ (". flag ");
$. Each (collection, function (){
$ (This). removeClass ("end ");
$ (This). addClass ("start ");
});
$ (Dom). removeClass ("start ");
$ (Dom). addClass ("end ");
}
</Script>

Css code:

Copy codeThe Code is as follows:
<Style type = "text/css">
. Start
{
Cursor: pointer;
Color: Green;
}
. End
{
Cursor: pointer;
Color: Red;
}
</Style>

Html code:

Copy codeThe Code is as follows:
<Span class = "flag" onclick = "dj (this)"> LoveOne </span>
<Span class = "flag" onclick = "dj (this)"> LoveTwo </span>
<Span class = "flag" onclick = "dj (this)"> LoveThree </span>
<Span class = "flag" onclick = "dj (this)"> LoveFour </span>

Isn't it very simple? The special effects are also very fun. You can play them freely and the scalability is still very strong. If you do anything more fun, please let me know.

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.