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/
精彩评论