/ 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('#myTable').click(function(e) { var clicked = $(e.target); clicked.css('background', 'red'); });