I'd like to use the id selector:
$("#id")
Is there a way to do this to only the nth element with that ID on the page? i.e.
$("#id:n")
jQuery :nth-of-type() SelectorThe :nth-of-type(n) selector selects all elements that are the nth child, of a particular type, of their parent. Tip: Use the :nth-child() selector to select all elements that are the nth child, regardless of type, of their parent.
jQuery :nth-child() SelectorThe :nth-child(n) selector selects all elements that are the nth child, regardless of type, of their parent. Tip: Use the :nth-of-type() selector to select all elements that are the nth child, of a particular type, of their parent.
You need to use "nth-last-child(2)" of jquery, this selects the second last element.
jQuery eq() Method The eq() method returns an element with a specific index number of the selected elements. The index numbers start at 0, so the first element will have the index number 0 (not 1).
There can be only ONE element with a given id in a page.
From the HTML norm :
There must not be multiple elements in a document that have the same id value.
Now suppose you want to get the nth element with a given class in your page, you may use eq :
$('.myclass').eq(index)
You can do like this:
$("#id:eq(n)")
But like @dystroy answer, it should be only 1 id in a page so you better using class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With