background preloader

Web

Facebook Twitter

AppJS - Waterfox. The 50 Free Apps We're Most Thankful For. Top 10 Clever Uses for Dropbox. Try MongoDB. HTML5 Playground. List Click Effect 2 - jsFiddle. In my last article, I described the common problem of events seemingly ceasing to work for new elements added to a document, whether by some form of ajax or by DOM modification. We examined one way to overcome the problem: Event Delegation.

With event delegation, we bind the event handler to a containing element that remains in the DOM and then check for the target of the event. Cloning Nodes This time, we'll take a look at re-binding event handlers. <ul id="list3" class="eventlist"> <li>plain</li> <li class="special">special <button>I am special</button></li> <li>plain</li></ul> We can make a copy of <li class="special"> and insert it after the original, while at the same time retaining any event handlers that were attached within the original. JavaScript: $(document).ready(function(){ $('#list3 li.special button').click(function(){var $parent = $(this).parent(); });}); Try it: plain special plain Note: I've added .append(' I\'m a clone!

') Try it now: plain special plain Re-binding Basics. KO Webmail.

Tools

HTML. CSS. Sites. Stuff. Design.