Reputation: 7
I'm new to jQuery and was confused by the concept of event handler, can someone give me an specific example?
Please correct me if I'm wrong:
$(document).ready(function(){
$('table').on('click', 'td', function () {
alert($(this).text());
});
});
Is the following function inside of this click event = "event handler"? or the "on(click)" is the event handler?
function(){alert($(this).text())}
Upvotes: 0
Views: 49
Reputation: 1294
Using the .on
method registers an event listener. That listener reacts when it hears an event has been triggered (that it was supposed to listen to). In that case the listener then hands the event it received over to the eventhandler, who handles the events. $(el).on('click'...
registers the listener to listen for click events on el. In ... function(event) {/*handle event*/});
the anynomous function is the eventhandler.
Upvotes: 2
Reputation: 410
Handler means the function, when you add click event the action performed by the function like
function(){alert($(this).text())}
is the event handler.
Upvotes: 0