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 ' > Names </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>");
Results after append:
$ (' #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);
});
jquery gets the dynamic elements after append: Live () and on ()