Anchor href Property - get the URL of a link for a relative URL - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Anchor href Property - get the URL of a link for a relative URL

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="default.asp">JavaScript and HTML DOM Reference</a></p>

<button onclick="myFunction()">display the value of the href attribute of the link above</button>

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

<script>
function myFunction() {//w  w w. j  av a  2  s.  c  o  m
    var x = document.getElementById("myAnchor").href;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials