Create a Map Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map

Introduction

You can create a <map> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/c.png" width="100" height="100" usemap="#myMap">

<button onclick="myFunction()">create an IMAGE-MAP and an AREA element with a link to "http://java2s.com"</button>

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

<script>
function myFunction() {/*from w  w w.  j  av  a2 s .c  o  m*/
    var x = document.createElement("MAP");
    x.setAttribute("id", "myMap");
    x.setAttribute("name", "myMap");
    document.body.appendChild(x);

    var y = document.createElement("AREA");
    y.setAttribute("href", "http://java2s.com");
    y.setAttribute("shape", "circle");
    y.setAttribute("coords", "120,50,10");
    document.getElementById("myMap").appendChild(y);

    document.getElementById("demo").innerHTML = "The MAP was created.";
}
</script>

</body>
</html>

Related Tutorials