Get Anchor Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


The Anchor object represents an HTML <a> element.

You can access an <a> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<a id="myAnchor" href="">Tutorials</a>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {//from w  ww .java  2 s.c  om
    var x = document.getElementById("myAnchor").href;
    document.getElementById("demo").innerHTML = x;


Related Tutorials