I used to manually bind the event handler when I added it. However, this function has been added to the new jquery version. We don't need to worry about it anymore.
Reference: http://api.jquery.com/live/
Previously, we defined events. For example, we wrote a click event for the element definition as follows:
Copy codeThe Code is as follows:
$ ('Input'). click (function (){
// Process the code
});
Or
Copy codeThe Code is as follows:
$ ('. Clickme'). bind ('click', function (){
// Bound handler called.
});
However, this can only be used to define events for the loaded elements. elements that are inserted later must be bound separately. Even if you use jquery's clone function, it cannot replicate events (so far, I still have no idea why it is defined like this, whether it cannot be copied or deliberately processed, to prevent some exceptions, it is still necessary to analyze the jquery source code ).
Now, you can easily use live,
$ ('. Clickme '). live ('click', function () {// Live handler called .}); in this way, even if you insert the elements dynamically behind it, it will be bound to an event, $ ('body '). append ('<div class = "clickme"> Another target </div> ');