How to check the serial number of element that have specific class using jquery?
-
09-10-2019 - |
Question
<ul>
<li class="res"></li>
<li class="res"></li>
<li class="res selected"></li>
<li class="res"></li>
</ul>
Using $('ul li.selected').length I can check total number of "selected elements" BUT I'd like to check the serial number of the "selected element" (in that case 3)
Can you help me do that.
Thanks
Solution
What exactly do you mean by serial number?
The content?
alert ( $('ul li.selected').text() );
The index?
var listItem = $('ul li.selected');
alert('Index: ' + $('ul li').index(listItem));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow