Devin Rhode
Devin Rhode

Reputation: 25377

How can I get the URL of a link?

How can I get the URL of a link?

$('.l').eq(0).href

is what I want to do, but it's undefined.


So given a jQuery selected anchor element, how do you get the href property?

Upvotes: 3

Views: 181

Answers (3)

Xeo
Xeo

Reputation: 357

I think this is what you're looking for $('.1 a')[0].href

Upvotes: 0

rafa
rafa

Reputation: 356

Are you sure you're selecting the link? Because I'm trying this in my site and ir works just fine:

    $('#id')[0].href 

I mean, are you sure the $('.l').eq(0) part is working?

Upvotes: 0

Igor Dymov
Igor Dymov

Reputation: 16470

Try:

$('.l').eq(0).attr("href")

Upvotes: 7

Related Questions