1.

How to add an event to an element in jQuery?

Answer»

.on() method attach an event handler function for one or more EVENTS to selected elements.

In the following code, the event handler function is attached to all the <TR&GT; elements in the table with id “#DATATABLE” on both click and mouseover events.

$('#dataTable tbody tr').on('click mouseover', function() {  console.log( $(this).text() ); });

It ALSO delegates the events to the elements dynamically added to the page, in this case, the event handler function will be attached to the dynamically added <TR> elements.



Discussion

No Comment Found