jo_dmg
Last Updated: February 25, 2016
·
454
· jacaetevha
D21ebccf20562e370eb0a8cf170a0580

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
Say Thanks
Respond