Create an Area Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Area

Introduction

You can create an <area> 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="#planetmap">

<map id="myMap" name="planetmap">
</map>/*ww w .j av a  2s .  c om*/

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

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

<script>
function myFunction() {
    var x = document.createElement("AREA");
    x.setAttribute("href", "http://java2s.com");
    x.setAttribute("shape", "circle");
    x.setAttribute("coords", "120,50,10");
    document.getElementById("myMap").appendChild(x);

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

</body>
</html>

Related Tutorials