开发者

how to use jquery index()

开发者 https://www.devze.com 2022-12-28 17:07 出处:网络
I开发者_StackOverflow中文版 am trying to find the index of the following element <ol id=\"parent\">

I开发者_StackOverflow中文版 am trying to find the index of the following element

<ol id="parent">
<li><a></a></li>
<li><a class="index_of_this"></a></li>
<li><a></a></li>
<li><a></a></li>
</ol>

But I keep getting -1

$('#parent a.index_of_this')

thank you for your help


To get an index of 1, do this:

$("a.index_of_this").parent().index();​ //1
//or this...
$("#parent").children(":has(.index_of_this)").index(); //1

You can play with it here


this worked!!

$('#parent li:has(a.index_of_this)').index()
0

精彩评论

暂无评论...
验证码 换一张
取 消