An id on an <area> tag assigns an identifier to the area.
The identifier must be unique across the page.
Three <area> tags, each one with a unique id.
<img src="/img/html/computer-map.png" alt="Computer" usemap="#computermap" />
<map name="computermap">
<area id="monitor" shape="rect" coords="253,142,16,2"
alt="Screen" href="javascript:alert('Screen was clicked');">
<area id="keyboard" shape="rect" coords="262,218,0,156"
alt="Keyboard" href="javascript:alert('Keyboard was clicked');">
<area id="mouse" shape="circle" coords="267,234,22"
alt="Mouse" href="javascript:alert('Mouse was clicked');">
</map>
The id attribute assigns an identifier to the <area> element.
The identifier must be unique across the page.
The id allows JavaScript to easily access the <area> element.
Tip: id is a global attribute that can be applied to any HTML element.
<area id="identifier" />
Value | Description |
---|---|
identifier | A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). |
An <area> with a unique id.
Clicking the button will display the area coordinates.
<img src="/img/html/computer-map.png" alt="Computer" usemap="#computermap">
<map name="computermap">
<area id="myarea" shape="rect" coords="253,142,16,2"
href="javascript:alert('Screen was clicked')"
alt="monitor" type="image/png">
</map>
<br/><br/>
<button onclick="show();">Show coordinates</button>
<script>
let show = () => {
let element = document.getElementById("myarea");
alert("Coordinates = " + element.coords);
}
</script>
The id attribute assigns a unique identifier for the <area>.
Clicking the button calls JavaScript which locates the <area> through the id.
Finally, the coordinates of the area are displayed in an alert box.
Here is when id support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <area>