Area coords Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Area

Description

The coords property sets or gets the value of the coords attribute of an area.

The coords attribute sets the x and y coordinates of an area.

Set the coords property with the following Values

Value Description
x1, y1, x2, y2 For shape "rect", sets the top-left corner and the bottom-right corner of the rectangle
x, y, radius For shape "circle", sets the circle center and the radius
x1, y1, x2, y2, .., xn, yn For shape "poly", sets the edges of the polygon. If the first and last coordinate pairs are not the same, the browser must add the last coordinate pair to close the polygon

Return Value

A String, representing a comma-separated list of coordinates

The following code shows how to Get the coordinates for a specific area in an image-map:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" width="145" height="126" usemap="#myMap">

<map name="myMap">
  <area id="myId" shape="circle" coords="125,60,10" alt="Venus" href="venus.htm">
</map>/*from  www. j a v a 2s .  co  m*/

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

<script>
function myFunction() {
    var v= document.getElementById("myId").coords;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials