JQuery table Row Discoloration

Source: Internet
Author: User
Tags html page

Many projects to improve the user experience require that the rows in the table be discolored when the mouse passes over. Often a project has a lot of songs table, whether we need to add a line color code for all table. If that's the case, it would be a very painful thing ...

First on the effect:



Js:

function Tdrowoverout (table) {

When the mouse passes
$ ("#" + table + "tr TD"). MouseOver (function () {
$ (this). The parent (). Find ("TD"). CSS ("Background-color", "#4fbb65"); Note: The background color of all TD in this row is changed
$ (this). The parent (). Find ("TD"). CSS ("Color", "#FFFFFF"); You can change the font color here if you want
$ (this). The parent (). Find ("TD a"). AddClass ("Whitecolor"); Some TD in addition to the hyperlink, resulting in the above changes in the font color for all a is invalid. Handled separately here
});


When the mouse is removed
$ ("#" + table + "tr TD"). Mouseout (function () {
var BGC = $ (This). Parent (). CSS ("Background-color"); Get TR background color
$ (this). The parent (). Find ("TD"). CSS ("Background-color", BGC); Change the background color of all TD. Here the reader can understand why the mouse is changed by the background color of the TD instead of the background color of TR
$ (this). The parent (). Find ("TD"). CSS ("Color", ' #000000 '); Restore Font Color
$ (this). The parent (). Find ("TD a"). Removeclass ("Whitecolor"); Restores the color of the hyperlink. (Whitecolor is a CSS class defined)
});
}


HTML page

<table id= "Tfactory" >

...

</table>


When used, simply call the table's ID as an argument and invoke the function above:

Tdrowoverout (' tfactory ')

Of course, the function itself can be optimized to make it more versatile, providing only one way of thinking


If you need to see the effect, you can see the effect on www.eorders.cn, the system (9 sqm management software) is done with ASP. You can click "View Demo" in the homepage to find a page with table.

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.