The difference between live and bind methods in jquery

Source: Internet
Author: User
Tags bind

  This article is mainly on the jquery live and bind methods of the difference between the detailed analysis of the introduction, the need for friends can come to the reference, I hope to help you.

Note that if you add layers and objects via JQ, you must use Live (), with no other effect   live's disadvantage is that after the run does not free space, too much use will take up more memory, bind () then click to release space   difference one:   Click here   can bind a simple click event to this element:   $ ('. ClickMe '). Bind (' click ', Function () {$ (' body '). Append ('   Another target '); ;    When the element is clicked, a warning box pops up. Then, imagine that another element has been added after this.   Although this new element can also match the selector ". ClickMe", because this element is added after calling. Bind (), clicking on this element will have no effect.   Live () provides a way to respond to this situation. If this is how we bind the Click event:   $ ('. ClickMe '). Live (' click ', function () {alert ("live handler called.");   then add a new element:   $ (' body '). Append ('   Another target ');    and then click on the new element, he can still trigger the event handler function.       Difference two:   (1) The Bind method can bind any JavaScript event, while the live method only supports click, DblClick, KeyDown when jQuery1.3. Keypress,keyup,mousedown, MouseMove, Mouseout, MouseOver, and MouseUp. In the jquery 1.4.1, the focus and blue events are even supported (mapped to more appropriate, And can bubble up on the Focusin and Focusout). In addition, hover (mapped to "MouseEnter MouseLeave") can also be supported in the jquery 1.4.1.   (2) Live () does not fully support elements found by means of DOM traversal. Instead, it should always be used directly behind a selector. Live () method.   (3) When an element uses the live method to bind the event, if you want to prevent the event from passing or bubbling, return false in the function, and simply invoke Stoppropagation () is not possible to prevent the event from passing or bubbling  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.