Document links Collection namedItem(id) - Get the URL of the element with id="myLink" in the document: - Javascript DOM

Javascript examples for DOM:Document links

Description

Document links Collection namedItem(id) - Get the URL of the element with id="myLink" 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   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>

Related Tutorials