Inside a .each() callback, is there any difference between this
and the second argument of the callback function?
For example, in the following code:
$("example").each( function(index, element) {
// body
});
is there any difference between this
and element
? Is the second argument just provided so you can choose a name?
Nope, there's no difference; the second argument is just for convenience.
Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.
from http://api.jquery.com/each/
Most likely, the second argument is provided for consistency with jQuery.each.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With