0

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}?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • 1
    Does this answer your question? [How to get "raw" href contents in JavaScript](https://stackoverflow.com/questions/1550901/how-to-get-raw-href-contents-in-javascript) – symlink Dec 26 '19 at 21:54

1 Answers1

1

getAttribute("href")

console.log(document.getElementById("a").getAttribute("href"))
<a id="a" href="/pages/index.html">Link</a>
symlink
  • 11,984
  • 7
  • 29
  • 50