The HTML DOM Map Object in HTML represents the <map> element.
Syntax
Following is the syntax −
Creating a <map> element
var mapObject = document.createElement(“MAP”)
Properties
Here, “mapObject” can have the following collections & properties −
| Collection/ Property | Description |
|---|---|
| areas | It returns a collection of all <area> elements |
| images | It returns a collection of all <img> & <object> elements |
| name | It sets/returns the value of the name attribute for <map> element |
Example
Let us see an example for Map areas collection −
<!DOCTYPE html>
<html>
<head>
<title>Map areas collection</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Map-areas-collection</legend>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/New7Wonders.jpg/276px-New7Wonders.jpg" width="250" height="150" usemap="#7Wonders">
<map id="WonderWorld" name="7Wonders">
</map>
<div id="divDisplay"></div>
<input type="button" value="Apply Link" onclick="myWonder()">
</fieldset>
</form>
<script>
function myWonder() {
var divDisplay = document.getElementById("divDisplay");
var newArea = document.createElement("AREA");
newArea.setAttribute("href", "https://en.wikipedia.org/wiki/Giza_pyramid_complex");
newArea.setAttribute("shape", "rect");
newArea.setAttribute("coords", "120,10,10,40");
document.getElementById("WonderWorld").appendChild(newArea);
divDisplay.textContent = "Link was applied, hover and click on pyramid of giza.";
}
</script>
</body>
</html>Output
This will produce the following output −
Before clicking ‘Apply Link’ button −

After clicking ‘Apply Link’ button −
