Bind Events To Dynamically Added Elements
I'm trying to bind functions to newly added elements using jquery...I have tried numerous examples online, but somehow nothing works for me. I created a form with id and a button,
Solution 1:
Got basically two options to do this:
Bind your events after appending the new html:
$(this).ajaxStop(function(){ $(this).after($(d).find(".edit-content").html()); // do you binding here });
Use event delegation (with .on() or .delegate()).
$('.some-container').on('click', '.edit-button', function(e) {...});
This will delegate the click event to an element .some-container for any children with class .edit-button, not matter the latter was already in the dom or loaded afterwards.
Post a Comment for "Bind Events To Dynamically Added Elements"