JQuery, get the first link of each <li>

I need a list of URLs to apply filters, and at the moment I'm writing $ ('. Classname a'), but now I only need the first link of each list. How to get this using jQuery?

+5
source share
2 answers

If the link is a direct child of the list, the best solution would be the following:

$('ul.classname > li > a:first-child')

I'm not sure, but I think that in other solutions you will get only one link (i.e. the first link of the first list). EDIT: yep, tested this, and :firstwill always return one element, not one for each matched parent element.

+6
source

CHILD ( , A) LI UL " ".

$("ul.classname > li:first-child")

http://pastebin.me/6865fdea79f3224c00a72e023f77a44a

0

All Articles