The Difference Between href
and getAttribute(‘href’) in JavaScript
For the HTML code <a id="aboutLink" href="/about/">about</a>, the document.getElementBy Id('aboutLink').href will return the full URL of the linked resource, for example http://somesite.com/about/.
If you want to get the exact value of the href attribute, you’d use document.getElementById('aboutLink').getAttribute('href'), which returns /about/. Yea, right – not in IE and Opera (both Win and Mac). See demo.