attach click event jquery dynamically code example
Example 1: document on click dynamic element
$(document).on('click', '.class', function() {
// do something
});
Example 2: jquery dynamic event handling
var counter = 0;
$("button").click(function() {
$("h2").append("<p class='test'>click me " + (++counter) + "</p>")
});
// With on():
$("h2").on("click", "p.test", function(){
alert($(this).text());
});