Example of using the jquery hover event to implement the table's interlace color function _jquery

Source: Internet
Author: User
jQuery Hover Events

Hover (Over,out) a method that mimics a hover event (the mouse moves over an object and removes it). This is a custom method that provides a "stay in" state for frequently used tasks.
When the mouse is moved above a matching element, the first specified function is triggered. When the mouse moves out of this element, the specified second function is triggered. Furthermore, it is accompanied by a detection of whether the mouse is still in a particular element (for example, an image in a div) and, if so, continues to remain in the hover state without triggering the move out event (fixed a common error using the Mouseout event).

Parameters:
Over (function): Mouse to move to the element to be triggered
Out (function): Moves the mouse out of the element to be triggered

Example:
Table with mouse hover plus a specific class

jQuery Code:
Copy Code code as follows:

$ (". Table_list tr"). Hover (
function () {
$ (this). addclass ("hover");
},
function () {
$ (this). Removeclass ("hover");
}

);

here are some points to pay attention to:

1,.hover is a class that wants to write what effect you want.

2, do not forget to introduce jquery.js file, otherwise it does not work also reported wrong.

3, compared to the traditional CSS, such as this.bgcolor= ' red ' such a way, a lot simpler, do not need to add a row of lines.

4, of course, can achieve the effect of odd and even different, readers themselves to study it.

One of the simpler ways to find out today is to use each of the jquery methods, which requires only one line of code to achieve an alternate color effect. It just doesn't change as the mouse moves.
Copy Code code as follows:

$ (". Tablist tr"). each (function (i) {this.style.backgroundcolor=[' #ccc ', ' #fff '][i%2]});

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.