我有一个 DIV
的列表是一个类似于下面的容器 DIV
。
<div id="ChainLinkList">
<div class="chainSelect" id="L2176">jj</div>
<div class="chainSelect" id="L2171">suby 3</div>
<div class="chainSelect" id="L2170">suby 2</div>
<div class="chainSelect" id="L2167">submenu</div>
</div>
我想在单击时获取特定 DIV
的顺序。我尝试了以下方法
$(".chainSelect").live("click", function() {
var index = $(this).parent().index(".chainSelect");
alert(index);
.....
还有
$(".chainSelect").live("click", function() {
var index = $('#ChainLinkList').parent().index(".chainSelect");
alert(index);
.....
但我好像只得到-1
最佳答案
您可以调用 $(this).index();
来获取被点击项在其父项中的索引:
$(".chainSelect").live("click", function() {
var index = $(this).index();
alert(index);
});
关于jquery - 获取div中div的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14068252/