Last Updated: February 25, 2016
·
627
· jacaetevha

Accessing an anchors full and relative path

In jQuery you can use the #prop method to get the full URL for an anchor, while using the #attr method to get the URL as it was specified in the anchor.

Given:

<a id='my-anchor' href='/path/to/page'>Click</a>

then:

$('#my-anchor').prop('href')

returns:

http(s)://your.server.com/path/to/page

and:

$('$my-anchor').attr('href')

returns:

/path/to/page