Click event for items dynamically added to the DOM

Before jQuery 1.8, I was able to use .live () to start when I clicked the button that jQuery had dynamically inserted.

Now, .on () and .bind () do not work for elements added to the DOM after the page loads.

What are the options now?

+5
source share
2 answers
$(parent_element).on("click", child_selector, function(evt) {
});

http://api.jquery.com/on/#direct-and-delegated-events

, -, . , , , , , . Model-View-Controller, , , . HTML-, , .

+14

,

$(document).delegate('click', "selector", function() {
    //your stuff
});
+2

All Articles