Javascript DOM HTML Area Object get

Introduction

The Area object represents an HTML <area> element.

We can access an <area> element by using getElementById():

var x = document.getElementById("myArea");

Click the button to get the URL of the area.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" width="100" height="100" usemap="#myFlagMap">

<map name="myFlagMap">
  <area id="myArea" 
        shape="circle" 
        coords="50,50,40" 
        alt="Target" 
        href="https://www.demo2s.htm">
</map>//from www .java  2 s  .c o m

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

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

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

</body>
</html>



PreviousNext

Related