Search code examples
javascripthtmlimagemap

how to get x1,y1,x2,y2 from map coords with javascript?


I have an image map and i want to have the x1,y1,x2,y2 separate in different variables, this is the map:

    <area shape="rect"
    coords="470,555,863,665"
    id="map"
    href="#"

this is how to get the coords out of it:

 var myVar = (document.getElementById("map").coords);

but the output of this line is "470,555,863,665" is it possible to separate them into different variables?

thanks


Solution

  • var coords = myVar.split(",");
    

    coords is now an array of the individual values in the comma separated list. So x1 = coords[0], y1 = coords[1], etc.