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

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -