Each function index and element

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

$('div').each(function(index, element) {
     is element equal to $(this)
});
+3
source share
2 answers

elementwill always match with this.

jsFiddle .

Also, wrapping it in $()will make it a jQuery object and will not equal another, even if you wrap another jQuery object.

There should never be a reason why you need to compare thiswith elementin this context.

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

$(this) thiswrapped by jquery object. Therefore, until thisit is equal $(this), you can still manipulate it with your heart content.

Here's what to see: http://jsfiddle.net/jomanlk/ZqXPn/

+3
source

All Articles