Code A
$('#tantoFaz').on('click', function() {
/* ....... */
});
Code B
$('#tantoFaz').click(function() {
/* ....... */
});
Code A
$('#tantoFaz').on('click', function() {
/* ....... */
});
Code B
$('#tantoFaz').click(function() {
/* ....... */
});
As shown, there is no difference. In fact, the click
function itself can be considered as a shortcut to the on
function, with the parameter click
, with some caveats. The click
function has three variations:
.click(handler)
Where handler
is a function that is executed for each event click
of the element. This variation is analogous to using .on("click", handler)
, as asked.
.click(eventData, handler)
The second variation receives an additional parameter eventData
. The operation of this variation is also analogous to the use of the on
function, although the data entered in eventData
will be passed as a parameter to handler
when the event is triggered.
.click()
The third variation, without parameters, is the one to be careful in this comparison, since its use is not similar to the on
function. What it does, in fact, is to trigger the click
event of the element in question, performing all the functions defined by the previous variations. This variation is analogous to .trigger("click")
.
So there is no difference between the codes presented in the question.
Reference: Official Documentation