Posted by & filed under PHP Development.

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.

Share on FacebookTweet about this on TwitterPin on PinterestDigg thisEmail this to someonePrint this page

Leave a Reply

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