.on() - jquery event handler


/ Published in: jQuery

.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):


Copy this code and paste it in your HTML
  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);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.