When you attach an event to a collection of elements using jQuery, the event will only affect elements which exist at that moment in time. For example:
// affects all matching elements which exist now $('.alreadyExists').click(someFunction); // this element will not have an onclick event $(newElement).addClass('alreadyExists');
In this scenario, if you wanted to add the event to the new element, you would need another line of code adding the click event to the element.
If you find yourself in this situation, you should try using jQuerys “Live” event handler instead. It provides a way of ataching events to all current and future elements which match the given selector. For example:
// works for elements created later $('.mightExist').live('click', someFunction); // as soon as the class is added, the element also gets the onclick event handler $(newElement).addClass('mightExist');




