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
Written by Jason Rogers
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Related Tags
#jquery
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#