So i came across a code like below:
var bindEvents = function () {
$("body").on('click', "a.class1, input.class2, button.class3", function () {
sendEvents($(this));
});
}
And i was wondering why would someone bind the event on body
here.
Can't we just do it by directly adding events on a
, input
and button
elements like this:
var bindEvents = function () {
$("a.class1, input.class2, button.class3").on('click', function () {
sendEvents($(this));
});
}
Is there any reason why one would use the 1st approach?