开发者

each function index and element

开发者 https://www.devze.com 2023-03-02 00:59 出处:网络
my question is a simple one how do you use element with index in each function $(\'div\').each(function(index, elem开发者_开发技巧ent) {

my question is a simple one how do you use element with index in each function

$('div').each(function(index, elem开发者_开发技巧ent) {
     is element equal to $(this)
});


The element there will always be the same as this.

jsFiddle.

Except wrapping it in $() will make it a jQuery object, and won't be equal to the other one, even if you wrap the other with a jQuery object.

There should never be a reason why you need to compare this to element in that context.


$('div').each(function(index, element) {
     //element != $(this)
     //element == this
});

$(this) is this wrapped by a jquery object. So while this won't equal $(this), you can still manipulate it to your heart's content

Here's something to look at : http://jsfiddle.net/jomanlk/ZqXPn/

0

精彩评论

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