admin管理员组文章数量:1352205
my question is a simple one how do you use element with index in each function
$('div').each(function(index, element) {
is element equal to $(this)
});
my question is a simple one how do you use element with index in each function
$('div').each(function(index, element) {
is element equal to $(this)
});
Share
Improve this question
asked May 3, 2011 at 5:03
ONYXONYX
5,87116 gold badges88 silver badges148 bronze badges
5
- 2 Your question might be simple if you added more details. Please add more details on what you're trying to do – JohnP Commented May 3, 2011 at 5:04
- The answer might be as simple as $(this) – JohnP Commented May 3, 2011 at 5:04
- 1 Ascii what you did there. But yeah - more info..? – Marty Commented May 3, 2011 at 5:05
- how do u use element in the collection there is no documentation about it – ONYX Commented May 3, 2011 at 5:06
- Try to give more information so that we are clear to answer your question. – Ariful Islam Commented May 3, 2011 at 5:11
2 Answers
Reset to default 3The 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 pare 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/jomanlk/ZqXPn/
本文标签: javascripteach function index and elementStack Overflow
版权声明:本文标题:javascript - each function index and element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743909287a2560092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论