Document links Collection [index] - Get the URL of the first link (index 0) in the document: - Javascript DOM

Javascript examples for DOM:Document links

Description

Document links Collection [index] - Get the URL of the first link (index 0) in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src ="" width="145" height="126" alt="" usemap ="#myMap">

<map name="planetmap">
  <area shape="rect" coords="0,0,80,130" href="" alt="">
  <area shape="circle" coords="90,60,5" href="" alt="">
  <area shape="circle" coords="120,60,10" href="" alt="">
</map>//from w w w. ja v  a 2  s  . c  o  m

<p>
  <a href="/html/default.asp">HTML</a><br>
  <a href="/css/default.asp">CSS</a>
</p>

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

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

<script>
function myFunction() {
    var x = document.links[0].href;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials