Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find position of <li>

Tags:

jquery

I am trying to find the position of Test3 in jquery can someone lead me down the right path please.

I need jquery to display 5

<ul id="numeric" class="sortable boxier" style="margin-right: 1em;">
<li>Test7</li>
<li>Test2</li>
<li>Test6</li>
<li>Test5</li>
<li>Test3</li>
<li>Test8</li>
</ul>

Thank you

like image 966
Rickstar Avatar asked Oct 07 '10 22:10

Rickstar


People also ask

How to get position of element in jQuery?

jQuery position() Method The position() method returns the position (relative to its parent element) of the first matched element. This method returns an object with 2 properties; the top and left positions in pixels.

What is eq in jQuery?

Definition and Usage. The :eq() selector selects an element with a specific index number. The index numbers start at 0, so the first element will have the index number 0 (not 1). This is mostly used together with another selector to select a specifically indexed element in a group (like in the example above).


1 Answers

$('li:contains(Test3)').index()

Note that this uses 0-based indexing, so it will actually display 4. You can add 1 if you want to start your count at 1.

like image 127
lonesomeday Avatar answered Oct 20 '22 06:10

lonesomeday