The On () method of the jquery event binds multiple selectors, multiple events

Source: Internet
Author: User
Tags bind


Such a requirement, if implemented with the live () method, is simple and easy to understand.

$ (' Nav li, #sb-nav Li, #help li '). Live (' click ', function () {//code ...});

After the 1.7 version of jquery, we recommend that you replace the previous bind, live, and delegate methods with the on method.
The above sentence, if used on, how to write it.

actually see live source code to know that live is actually entrusted doucment for event delegation.
According to this idea, you can bind the on method to the document.

$ (document). On (' Click ', ' #header. Fixed-feedback-bn, #sb-sec. Feedback-bn ', function () {//code ...});

In another case, the on () method binds multiple events and can be written like this:

$ ("Table.planning_grid"). On ({mouseenter:function () {//Handle MouseEnter ...}, Mouseleave:function () {//Handle mouse Leave.}, Click:function () {//Handle click ...}}, "TD");

Finally, multiple selectors are bound with the On () method, and multiple events can be written like this:

$ (document). On ({mouseenter:function () {//Handle MouseEnter ...}, Mouseleave:function () {//Handle MouseLeave ...}, c Lick:function () {//Handle click ...}}, ' #header. Fixed-feedback-bn, #sb-sec. feedback-bn ');

Reprint Please specify: Green Bean Front»jquery event on () method binds multiple selectors, multiple events

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.