My goal is to choose a specific set of anchor elements using the nth-child pseudo selector. However, I am facing an issue because nth-child only works with child elements, and my structure looks like this:
<div>
<a>first link>
</div>
<div>
<a>Second link</a>
</div>
<div>
<a>Third link</a>
</div>
In this scenario, the selector that I thought would work for selecting the first 2 matched elements fails to do so:
$("a:nth-child(n+1):nth-child(-n+2)")
I have provided an example here: http://jsfiddle.net/o6w5orom/, where in the initial example, all elements are returned instead of just the first 2. In the second one, it works, but only on direct children.
Therefore, I am wondering if there is a way to create a CSS selector for jQuery that can return a range of elements, similar to nth-child, but functioning on matched elements of a jQuery object? I am looking to construct the selector without having to write logic to process a jQuery object.