Get the URL of the element with id="myLink"
in the document:
var x = document.links.namedItem("myLink").href;
Click the button to display the URL of the element with id="myLink"
.
<!DOCTYPE html> <html> <body> <img src ="image1.png" width="145" height="126" alt="Circle" usemap ="#myFlagMap"> <map name="myFlagMap"> <area shape="rect" coords="0,0,30,30" href="https://java2s.com" alt="Site"> <area shape="circle" coords="90,58,30" href="https://java2s.com" alt="Web"> <area shape="circle" coords="50,50,40" href="https://www.java2s.com" alt="Target"> </map>//from w ww .ja va2 s . c o m <p> <a id="myLink" href="https://java2s.com">HTML</a><br> <a href="https://java2s.com">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>