Javascript DOM HTML Anchor href Property get

Introduction

Click the button to display the value of the href attribute of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.example.com">examples</a></p>

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

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

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

}
</script>

</body>
</html>



PreviousNext

Related