Posted By

grindking on 10/31/12


Tagged

event jquery handler EventHandler


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrockSamsom


.on() - jquery event handler


 / Published in: jQuery
 

URL: http://api.jquery.com/on/

.on( events [, selector] [, data], handler(eventObject) )

A delegated-events approach attaches an event handler to only one element, the tbody, and the event only needs to bubble up one level (from the clicked tr to tbody):

  1. $("#dataTable tbody").on("click", "tr", function(event){
  2. alert($(this).text());
  3. });
  4.  
  5.  
  6.  
  7.  
  8. /////
  9. function notify(){
  10. alert("clicked");
  11. }
  12.  
  13. $("button").on("click", notify);

Report this snippet  

You need to login to post a comment.