jquery bind to dynamically added elements code example
Example 1: javascript bind event to created element
document.addEventListener('click', function(e){
if(e.target && e.target.id== 'myDynamicallyAddedElementID'){
}
});
$(document).on('click','#myDynamicallyAddedElementID',function(){
});
Example 2: jquery dynamic event handling
var counter = 0;
$("button").click(function() {
$("h2").append("<p class='test'>click me " + (++counter) + "</p>")
});
$("h2").on("click", "p.test", function(){
alert($(this).text());
});