Differences between. band (). live (). delegate (). on () in jquery, jquery. band

Source: Internet
Author: User

Differences between. band (). live (). delegate (). on () in jquery, jquery. band

 

 

Bind (type, [data], fn) binds an event handler function to a specific event of each matching element.

$ ("A"). bind ("click", function () {alert ("OK ");});

Live (type, [data], fn) attaches an event handler function to all matching elements, even if the element is added later

$ ("A"). live ("click", function () {alert ("OK ");});

Delegate (selector, [type], [data], fn) adds one or more event handlers to the specified Element (child element of the selected element, and specify the function to run when these events occur

$ ("# Container"). delegate ("a", "click", function () {alert ("OK ");})

On (events, [selector], [data], fn) binds one or more event handlers to the selected element.

Differences:

@ 1. bind () is directly bound to the element

@ 2. live () is bound to an element by means of bubbling. More suitable for the list type, bind to the document DOM node. And. bind () support dynamic data.

@ 3. delegate () is a more precise event proxy in a small scope, with better performance than. live ()

@ 4. on () is the latest version 1.9 integrated with the previous three methods of new event Binding Mechanism

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.