开发者

jQuery .each() this and element

开发者 https://www.devze.com 2023-03-13 18:09 出处:网络
Inside a .each(开发者_高级运维) callback, is there any difference between this and the second argument of the callback function?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消