Javascript examples for DOM:Document links
Document links Collection item(index) - Get the URL of the first link (index 0) in the document:
<!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. j ava 2s.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.item(0).href; document.getElementById("demo").innerHTML = x; } </script> </body> </html>