HTMLMapElement: areas property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính chỉ đọc areas của giao diện HTMLMapElement trả về một tập hợp các phần tử <area> được liên kết với phần tử <map>.

Giá trị

Một đối tượng HTMLCollection của các phần tử HTMLAreaElement.

Ví dụ

html
<map id="image-map" name="image-map">
  <area shape="circle" coords="50,50,35" href="#left" alt="left arrow" />
  <area shape="circle" coords="150,50,35" href="#right" alt="right arrow" />
</map>
<img
  usemap="#image-map"
  src="left-right-arrow.png"
  alt="left right arrow image" />
<output></output>
js
const mapElement = document.getElementById("image-map");
const outputElement = document.querySelector("output");

for (const area of mapElement.areas) {
  area.addEventListener("click", (event) => {
    outputElement.textContent = `You clicked on the ${area.alt} area.\n\n`;
  });
}

Kết quả

Thông số kỹ thuật

Thông số kỹ thuật
HTML
# dom-map-areas-dev

Tương thích trình duyệt

Xem thêm