Get local href value from anchor (a) tag Get local href value from anchor (a) tag javascript javascript

Get local href value from anchor (a) tag


The below code gets the full path, where the anchor points:

document.getElementById("aaa").href; // http://example.com/sec/IF00.html

while the one below gets the value of the href attribute:

document.getElementById("aaa").getAttribute("href"); // sec/IF00.html


document.getElementById("link").getAttribute("href");If you have more than one <a> tag, for example:

<ul>  <li>    <a href="1"></a>  </li>  <li>    <a href="2"></a>  </li>  <li>    <a href="3"></a>  </li></ul>