मानचित्र क्षेत्रों का संग्रह
उदाहरण
पता लगाएँ कि एक विशिष्ट छवि-मानचित्र में कितने <क्षेत्र> तत्व हैं:
var x = document.getElementById("planetmap").areas.length;
एक्स का परिणाम होगा:
3
नीचे और अधिक "इसे स्वयं आज़माएं" उदाहरण।
परिभाषा और उपयोग
क्षेत्र संग्रह छवि-मानचित्र में सभी <क्षेत्र> तत्वों का संग्रह देता है।
नोट: संग्रह में तत्वों को सॉर्ट किया जाता है जैसे वे स्रोत कोड में दिखाई देते हैं।
युक्ति: सभी <क्षेत्र> तत्वों के संग्रह को वापस करने के लिए जिसमें एक href विशेषता निर्दिष्ट है, लिंक संग्रह का उपयोग करें।
ब्राउज़र समर्थन
Collection | |||||
---|---|---|---|---|---|
areas | Yes | Yes | Yes | Yes | Yes |
वाक्य - विन्यास
mapObject.areas
गुण
Property | Description |
---|---|
length | Returns the number of <area> elements in the collection. Note: This property is read-only |
तरीकों
Method | Description |
---|---|
[index] | Returns the <area> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <area> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <area> element from the collection with the specified id. Note: Returns null if the id does not exist |
टेक्निकल डिटेल
डोम संस्करण: | कोर स्तर 2 दस्तावेज़ वस्तु |
---|---|
प्रतिलाभ की मात्रा: | एक HTMLCollection ऑब्जेक्ट, दस्तावेज़ में छवि-मानचित्र में सभी <क्षेत्र> तत्वों का प्रतिनिधित्व करता है। संग्रह में तत्वों को क्रमबद्ध किया जाता है क्योंकि वे स्रोत कोड में दिखाई देते हैं |
और ज्यादा उदाहरण
उदाहरण
[ सूचकांक ]
छवि-मानचित्र में पहले <क्षेत्र> तत्व का URL प्राप्त करें:
var x = document.getElementById("planetmap").areas[0].href;
एक्स का परिणाम होगा:
https://www.w3schools.com/jsref/sun.htm
उदाहरण
आइटम ( सूचकांक )
छवि-मानचित्र में पहले <क्षेत्र> तत्व का URL प्राप्त करें:
var x = document.getElementById("planetmap").areas.item(0).href;
एक्स का परिणाम होगा:
https://www.w3schools.com/jsref/sun.htm
उदाहरण
नामित आइटम ( आईडी )
छवि-मानचित्र में id="myArea" के साथ <क्षेत्र> तत्व का URL प्राप्त करें:
var x = document.getElementById("planetmap").areas.namedItem("myArea").href;
एक्स का परिणाम होगा:
https://www.w3schools.com/jsref/mercur.htm
उदाहरण
एक छवि-मानचित्र में सभी <क्षेत्र> तत्वों के माध्यम से लूप करें और प्रत्येक क्षेत्र के आकार को आउटपुट करें:
var x = document.getElementById("planetmap");
var txt = "";
var i;
for (i = 0; i < x.areas.length; i++) {
txt = txt + x.areas[i].shape + "<br>";
}
txt का परिणाम होगा:
rect
circle
circle
❮ नक्शा वस्तु