0
$(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

user2507316
  • 159
  • 4
  • 14
  • Event delegation... or bind the handlers to them when you add them. – PSL Oct 03 '13 at 01:48
  • possible duplicate of [Direct vs. Delegated - jQuery .on()](http://stackoverflow.com/questions/8110934/direct-vs-delegated-jquery-on) – PSL Oct 03 '13 at 01:49

1 Answers1

3

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(){

});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107