获取所选元素的位置,而不是DOM中元素的索引 [英] Get position of selected elements, not index of element in DOM
本文介绍了获取所选元素的位置,而不是DOM中元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div>
<h3>Heading one</h3>
<h3>Heading two</h3>
<h4>heading caption</h4>
<h3>Heading three</h3>
</div>
我想获得元素的位置jQuery选择,而不是它在DOM中的索引。
I want to get the position of the element within the jQuery selection, rather than it's index in the DOM.
目前,如果我 alert($(h3)。eq(2) ).index());
我会'3' - 我想要'2'。
At the moment, if I alert($("h3").eq(2).index());
I'll get '3' - I want '2'.
推荐答案
传递你的索引()一个选择器:
Pass your index() a selector:
alert($("h3").eq(2).index("h3"));
这篇关于获取所选元素的位置,而不是DOM中元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文