Return to Snippet

Revision: 43121
at March 17, 2011 06:00 by housecor


Initial Code
$('#myTable').click(function(e) {  
    var clicked = $(e.target);  
    clicked.css('background', 'red');  
});

Initial URL


Initial Description
Note that this is more efficient than binding an event to every individual TD. Plus, as a bonus, any new TD's added are bound with this method. When using event delegation you can add as many matching elements to the DOM as you like after the event is bound and they work too. e holds a reference to the element that was clicked.

Initial Title
jQuery event delegation

Initial Tags


Initial Language
jQuery