Select the <a> which is the second <a> on the page containing the same href text? JQuery

I am working with a page that contains multiple links containing the same href text and I need to select the second anchor element in the page containing the specified href text. Here's a simplified version of the link structure on the page:

<a href="same/link/to/stuff/">same link</a>
<a href="same/link/to/stuff/">same link</a>

      

How do I moderate my selector so that it only selects the second anchor in the above example?

I am currently trying:

$('a[href=same/link/to/stuff/] :eq(1)')

      

but it doesn't work.

Thanks!!

+2


a source to share


1 answer


As Patrick Karcher pointed out , you are missing a forward slash.

Also, you shouldn't have a space before :eq(1)

.

$('a[href=same/link/to/stuff/]:eq(1)');

      



Spaces in selectors imply that the element after the space is a descendant of the element before the space.

As you did, you were trying to select the second element of the descendant a[href=same/link/to/stuff/]

.

+1


a source







All Articles