The example in this article describes how jQuery binds events to dynamically added elements. Share it with everyone for your reference. The specific analysis is as follows:
Binding events in jquery generally use bind or click, but this can only define events for elements that have been loaded, and elements that are added and inserted later need to be bound separately. Use live before version 1.7. However, it is recommended to use on after version 1.8. Here is an introduction to how to bind events to dynamically added elements in jQuery
In actual development, you will encounter situations where you need to bind trigger events to dynamically generated html elements
For example
<div id="testdiv"> <ul></ul> </div>
You need to add a click event to the
$("#testdiv ul li").live("click",function(){ });
After jquery version 1.7, use on to dynamically bind events
$("#testdiv ul").on("click","li", function() { //do something here });
I hope this article will be helpful to everyone’s jQuery programming.