cycling jQuery_Succinctly | Page 76

{ $(this).after(""); }); })(jQuery); After examining the code, it should be obvious that we are using live() to apply event delegation to a parent element ( element in the code example) so that any button element added to the DOM always responds to the click handler. To remove the live event, we simply use the die() method—e.g. $('button').die(). The concept to take away is the live() method could be used to attach events to DOM elements that are removed and added using AJAX. In this way, you would forgo having to rebind events to new elements introduced into the DOM after the initial page load. Notes: live() supports the following handlers: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup. live() only works against a selector. live() by default will stop propagation by using return false within the function sent to the live() method. Adding a function to several event handlers It is possible to pass the event bind() method several event handlers. This makes it possible to attach the same function, written once, to many handlers. In the code example below, we attach a single anonymous callback function to the click, keypress, and resize event handlers on the document. Sample: sample72.html 76