Jquery controls the color of even rows in a table or list

Source: Internet
Author: User

Demo7.
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This). removeClass ("over") ;}) // remove the class of the row
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
In terms of the effect, I added a line to the color:
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This). removeClass ("over") ;}). click (function () {// remove the class of the row
$ (This ). toggleClass ("click "). removeClass ("alt")}) // click to change the color. Note: because there is a line to change the color, you must remove ("alt") When toggleClass is triggered ").
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
Speaking of this, I have to mention the difference between toggle and toggleClass:
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This ). removeClass ("over ");}). toggle (function () {$ (this ). addClass ("click") ;}, function () {$ (this ). removeClass ("click ");}). unbind ("click ")
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
We can find that:
ToggleClass: it can be found that the hyper-connection can still be connected, not occupied by toggle and click
Toggle: it can be found that the super connection is no longer available, so toggle is not suitable for this situation. However, you can unbind a click ("click"). The amount of code seems to be much larger than that of toggleClass in combination with click, so I chose toggleClass.

From: http://hi.baidu.com/hbjinzhao/blog/item/7609123b481d33e714cecb2c.html

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.