Reputation: 169
$(function(){
$('#somelement').click(function(){
//do stuff
});
});
This code don't work on elements that have appeared a bit later, how to make this bind to all elements that will appear in the future
Upvotes: 0
Views: 849
Reputation: 57095
Use .on()
As your content is added dynamically so it is not accessible directly ,So you have to use Event delegation.
$(document).on('click','#somelement',function(){
});
or
you can bind the Event delegation to the parent element of the new element which is present in DOM at the of time DOM ready or page load.
$('#parentID').on('click','#somelement',function(){
});
Upvotes: 3