Getting an anchor element's absolute URL with jQuery

Chetan picture Chetan · May 30, 2011 · Viewed 10k times · Source

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

Answer

Andrew Whitaker picture Andrew Whitaker · May 30, 2011

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;