I need a list of URLs to apply filters to and at the moment I write $('.classname a') but now I need only the first link of each list. How do I get this using jQuery?
+5
A:
If the link is a direct child of the list, then the best solution would be:
$('ul.classname > li > a:first-child')
I'm not sure but I think the other solutions will only get you one link (i.e. the first link of the first list). EDIT: yep, tested this and :first will always return one element, not one for each parent element matched.
DisgruntledGoat
2010-04-08 09:31:45
I cant believe i got 3 of the same wrong answers. Thanks. +1 and accept.
acidzombie24
2010-04-08 09:37:06
A:
The following will match the first CHILD (most likely your A) in the first LI in every UL with class "classname".
$("ul.classname > li:first-child")
Fabian
2010-04-08 09:43:17