+ 1
How do I get the href of an anchor with JS?
I'm making a scroll animation. But I've made it with jQuery (it seems easier), but I don't know how do it with pure JS. In case, I have a menu list, and I get the href anchor to move the page up and down.
1 Answer
+ 6
<a id="anchor" href="src/a.html">
document.getElementById("anchor").getAttribute("href"); // Gets actual string 'src/a.html'.
document.getElementById("anchor").href; // Gets full path 'http://mydomain.com/src/a.html'.