New elements added to the document after binding your events do not automatically receive these event handlers. One way to fix this - as John Millikin says - is to recreate events after creating new elements.
Another standard way is event delegation. Since events go all the way up and down the stack through all their parent elements, you can bind the event to an element that will be the ancestor of all your target elements.
For example, this jQuery code will work (your syntax may differ for other JavaScript libraries):
$(document).ready(function() { $('body').click(function(event) { if ($(event.target).is('.foo')) {
Now, when you click something from the foo class, this event will be fired unless something between them catches the event and cancels the bubble. In fact, an event will be raised when almost anything is pressed - the if statement simply filters out which events deserve a warning.
Neall source share