If <a href="{relative path}">...</a>
is specified in a page's HTML the a.href
property in Chrome's JavaScript returns an absolute path with the current document.URL
.
I know I can extract the relative path portion from there with a combination of replace()
, substr()
, indexOf()
, but I'd like to avoid this. Is there a property/function that returns exactly that what the HTML page developer defined as {relative path}
?
getAttribute("href")
console.log(document.getElementById("a").getAttribute("href"))
<a id="a" href="/pages/index.html">Link</a>