[英]Get index/position of element and it's Name in Javascript [ DOM ]
[英]Get position of selected elements, not index of element in DOM
<div>
<h3>Heading one</h3>
<h3>Heading two</h3>
<h4>heading caption</h4>
<h3>Heading three</h3>
</div>
我想在jQuery選擇中獲取元素的位置,而不是它在DOM中的索引。
此刻,如果我alert($("h3").eq(2).index());
我會'3' - 我想'2'。
傳遞index()一個選擇器:
alert($("h3").eq(2).index("h3"));
<div>
<h3>Heading one</h3>
<h3>Heading two</h3>
<h4>heading caption</h4>
<h3>Heading three</h3>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("div").children().each(function(){
$(this).click(function(){
alert($(this).context.innerHTML);
});
});
});
</script>`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.