JQuery nth id / class element

I would like to use the id selector:

$("#id") 

Is there a way to do this only for the nth element with this id on the page? i.e.

 $("#id:n") 
+7
source share
3 answers

A page can have only one element with a given identifier.

From the HTML standard :

The document should not have several elements having the same id.

Now suppose you want to get the nth element with a given class on your page, you can use eq :

 $('.myclass').eq(index) 
+26
source

You can do the following:

 $("#id:eq(n)") 

But, as @dystroy answer, it should be only 1 id per page, so you better use a class.

+3
source

You can use the :eq(n) selector to get the nth element, but the identifier must be unique.

You must use the class attribute to group similar elements.

+2
source

All Articles