1// bind click handler to element that is added later/dynamically
2document.addEventListener('click', function(e){
3 if(e.target && e.target.id== 'myDynamicallyAddedElementID'){
4 //do something
5 }
6});
7
8//Alternatively, if your using jQuery:
9$(document).on('click','#myDynamicallyAddedElementID',function(){
10 //do something
11});
12