The difference between the. bind (). Live (). Delegate () on () in jquery.

Source: Internet
Author: User

Bind (TYPE,[DATA],FN) binds event handlers for specific events of each matching element

$ ("a"). Bind ("click", Function () {alert ("OK");});

With $ ("a"). Click (function () {...}); Different usages, but bind can bind multiple events and can also be unbound

$ (selector). Bind ({event:functionevent:function, ...});

Live (TYPE,[DATA],FN) attaches an event handler function to all matching elements, even if the element is added later in the

The event handlers attached through the live () method apply to the current and future elements of the matching selector (such as new elements created by the script).

Multiple bindings cannot be used before 1.4.0 (not including 1.4.0), and a single example is: $ ("a"). Live ("Click", Function () {alert ("OK");});
In 1.4.0-1.4. 2 began to support, the example is as follows: $ ('. Hoverme '). Live (' mouseover mouseout ', function (  event) {if (Event.type = = ' MouseOver ')    {// do something on mouseover  Else  {    // do something on mouseout  }});
Theversion after 1.4.3 has started to support another method of updating:
$ (selector). Live ({event:functionevent:function

Delegate (SELECTOR,[TYPE],[DATA],FN) The specified element (which belongs to the child element of the selected element) adds one or more event handlers and specifies the function to run when these events occur

Event handlers that use the delegate () method apply to current or future elements, such as new elements created by a script.

$ ("#container"). Delegate ("A", "click", Function () {alert ("OK");})

On (EVENTS,[SELECTOR],[DATA],FN) an event handler that is bound to one or more events on the selection element

$ (selector). On ({event:function, event:function, ...})

Difference:

. Bind () is directly bound on the element

. Live () is bound to an element by bubbling way. More appropriate for the list type, bound to the document DOM node. and. Bind () have the advantage of supporting dynamic data.

. Delegate () is a more precise, small-scale use of event proxies with better performance. Live ()

. On () is the latest 1.9 version of the new event binding mechanism that incorporates the previous three ways

The difference between the. bind (). Live (). Delegate () on () in jquery.

Related Article

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.