After adding elements dynamically with jquery, it is not possible to trigger events for dynamically added elements. The solution is as follows:
Method One: Bind the Live event (the live event is only supported under jquery1.9, not supported in the high version).
123 |
$(".newBtn").live("click",function(){ ///jquery 1.9(不包括1.9)以下可以 alert(‘这里是动态元素添加的事件‘); }) |
method Two: Take advantage of the on () event binding ($ (Parentele). On ("click", ". Thisele", function () {})
123 |
$ ("Body"). On ("click", ". Newbtn", function () { alert ( ' Here is an event added by dynamic Element '); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; br >// The Parentele here is Thisele's father or ancestor element, Parentele can be document, body, etc. < br >< BR >< BR >//Note: If the function called at this time is an externally defined function, do not add () at the time of the call, or skip the click event directly triggering the function |
$ ("Body"). On ("click", ". Newbtn", AA);
function aa () {
Alert (' Here is the event of dynamic element addition ');
}
jquery dynamic add element failed to trigger binding event