Jquery: find out in what position (order) a certain element is among its neighbors

I think it should be simple, but I could not understand:

I have a container with a couple of children:

<div id='container'>
  <div id='one'>some</div>
  <div id='two'>random</div>
  <div id='three'>text</div>
</div>

I want to know the position of the word element ('# two') ... which should return 2 (since this element is the second of the children of the container, $ ('# one') ... should return 1, etc.

Thank you very much in advance,

Martin

+3
source share
1 answer

You can use jQuery.index for this:

$('#two').index() // 1

Note that the index is based on zero.

+7
source

Source: https://habr.com/ru/post/1788826/


All Articles