Javascript examples for DOM:Document links
Document links Collection namedItem(id) - Get the URL of the element with id="myLink" 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 www . j ava 2s.c o m <p> <a id="myLink" 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.namedItem("myLink").href; document.getElementById("demo").innerHTML = x; } </script> </body> </html>