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

Source: Internet
Author: User

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

$ ("ul"). Append ("<li class= ' name ' > </li>");   

"Error" is then done in the following way, which is not available:

$ (". Name"). Click (function () {Alert ("node acquired after append");})   

The correct way to do this is:

$ (". Name"). Live ("click", Function () {alert ("acquired");});  

After jquery 1.7+, use on instead of the Live,on () method to add one or more event handlers on the selected element and child elements

<div id= "One" ></div>$ (' #one '). Append ("<P id= ', ' >test1</p>" ); Append results: $ (' #one '). Append ("<P id= ', ' >test1</p>");      

"Error" will not pop up in the following way directly:

$ ("#two"). On ("click", Function (data) {alert (data);}); 

"Correct" is changed to the following way:

$ ("body"). On ("click","#two", function (data) {alert (data);});  

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

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.