Posted By

housecor on 03/17/11


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


jQuery event delegation

 / Published in: jQuery

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.

  1. $('#myTable').click(function(e) {
  2. var clicked = $(;
  3. clicked.css('background', 'red');
  4. });

Report this snippet  

You need to login to post a comment.