开发者

jQuery .each() this and element

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜