Get Anchor Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Introduction

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>
<html>
<body>

<a id="myAnchor" href="https://www.java2s.com">Tutorials</a>

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

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

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

</body>
</html>

Related Tutorials