javascript - How to find the position for an element in a li with jquery or vanilla js -


lets imagine have following html code.

i need find position within li elements li has class focus applied.

in example result should 2 (if @ 0 index). idea how it?

<ul class="mylist">     <li>milk</li>     <li>tea</li>     <li class="focus">coffee</li> </ul> 

use .index()

var index = $('.focus').index(); 

demo

specific list

$('.mylist .focus').index() 

demo


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -