Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an anchor element's absolute URL with jQuery

Given an anchor element (with something like $("a:first")), how do you get the absolute URL that the anchor points to?

like image 740
Chetan Avatar asked May 30 '11 01:05

Chetan


1 Answers

If you're using jQuery 1.6+, you can use .prop():

$("a:first").prop("href")

Prior to 1.6, you can access the href property directly on the DOM element:

$("a:first")[0].href;
like image 107
Andrew Whitaker Avatar answered Oct 03 '22 01:10

Andrew Whitaker