Inherit jQuery Functionality for Dynamic Additions

Our latest project requires a lot of event driven functionality which attempts to reuse click() functions. Unfortunately when you dynamically add an element to the DOM it does not automatically inherit any functions that were loaded in $(document).ready(). For example: if you have a text-box and an “add” button (A) which, when clicked, adds a new select-box with another “add” button (B) to add items to the select-box, (B) will not be able to perform the correct action if you pre-loaded the event.  In these cases, instead of using $(“#B”).click(function(){…}); use $(“#B”).live(“click”, function(){…});  Hopefully this solves some peoples problems!  You can read more about this at jQuery.com.

Leave a Reply

Your email address will not be published. Required fields are marked *