Resolves an invalid method for element events added using jquery with append

Source: Internet
Author: User

When we use jquery to dynamically load HTML elements, but the elements are bound to events such as click, which are not valid for the newly added elements, how should they be resolved?

Live method

Live (Type, fn)
The new method in JQuery 1.3. Binds an event handler function (such as a click event) to all current and future matching elements. Custom events can also be bound.
Currently supports click, DblClick, MouseDown, MouseUp, MouseMove, MouseOver, Mouseout, KeyDown, KeyPress, KeyUp.
Not yet supported Blur, Focus, MouseEnter, MouseLeave, change, submit
Unlike bind (), Live () can only bind one event at a time.

This approach is similar to traditional bind, except that binding events with live will bind events to all current and future elements on the page (using delegation). For example, if you bind the click event to all Li on the page with live. Then, when you add an Li to this page later, the Click event is still available for this newly added Li. Instead of having to re-bind events to this newly added element. For example, the following code.

12345678910111213141516
On method

But with the jquery version upgrade, since jquery 1.9 and above have been unable to use live, then there is no way, no, for the jQuery1.9 version and above can use on, the effect is equivalent to live. How to use the following on

1234567
<script>$(document).On("Click",". Waiting-save",function(){ $(This).html @T (" Saving ... " ") $ (). attr disabled" , )  (this) ; };</script>          

This article link address: resolves an invalid method for element events added using jquery with append

Resolves an invalid method for element events added using jquery with append

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.