How to get the first href li link in ul list in jQuery
I have the following list
<ul class="tabs"> <li><a href="testlink.php">First link</a></li> <li><a href="testlink2.php">Second link</a></li> </ul> I would like to capture href for the first link. This link should be in the var link, so I can use it to dynamically retrieve the contents of the page. Thanks for any help :)
+6
topbennie
source share3 answers
$(function() { var href = $('ul.tabs').find('a').slice(0,1).attr('href'); }); This is pretty fast if you try to avoid Sizzle selectors after execution:
+4
jAndy
source sharejust like
var link = $(".tabs li:first a").attr("href"); 0
RobertPitt
source share