jquery dynamic event handling code example
Example 1: 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());
});
Example 2: change event doesn't work on dynamically generated elements .
$( "#dataTable tbody" ).on( "click", "tr",
function() {
console.log( $( this ).text() );
});