Harita alanları Koleksiyonu
Örnek
Belirli bir görüntü haritasında kaç tane <area> öğesi olduğunu öğrenin:
var x = document.getElementById("planetmap").areas.length;
x'in sonucu şöyle olacaktır:
3
Aşağıda daha fazla "Kendiniz Deneyin" örnekleri.
Tanım ve Kullanım
Alanlar koleksiyonu, bir görüntü haritasındaki tüm <area> öğelerinin bir koleksiyonunu döndürür.
Not: Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır.
İpucu: Belirtilen href özniteliğine sahip tüm <area> öğelerinin bir koleksiyonunu döndürmek için bağlantı koleksiyonunu kullanın.
Tarayıcı Desteği
Collection | |||||
---|---|---|---|---|---|
areas | Yes | Yes | Yes | Yes | Yes |
Sözdizimi
mapObject.areas
Özellikler
Property | Description |
---|---|
length | Returns the number of <area> elements in the collection. Note: This property is read-only |
yöntemler
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 |
Teknik detaylar
DOM Sürümü: | Çekirdek Düzey 2 Belge Nesnesi |
---|---|
Geri dönüş değeri: | Belgedeki bir görüntü haritasındaki tüm <area> öğelerini temsil eden bir HTMLCollection Nesnesi. Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır. |
Daha fazla örnek
Örnek
[ dizin ]
Bir görüntü haritasındaki ilk <area> öğesinin URL'sini alın:
var x = document.getElementById("planetmap").areas[0].href;
x'in sonucu şöyle olacaktır:
https://www.w3schools.com/jsref/sun.htm
Örnek
öğe ( dizin )
Bir görüntü haritasındaki ilk <area> öğesinin URL'sini alın:
var x = document.getElementById("planetmap").areas.item(0).href;
x'in sonucu şöyle olacaktır:
https://www.w3schools.com/jsref/sun.htm
Örnek
nameItem( id )
Bir resim haritasında id="myArea" ile <area> öğesinin URL'sini alın:
var x = document.getElementById("planetmap").areas.namedItem("myArea").href;
x'in sonucu şöyle olacaktır:
https://www.w3schools.com/jsref/mercur.htm
Örnek
Bir görüntü haritasındaki tüm <area> öğeleri arasında dolaşın ve her alanın şeklini çıkarın:
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'nin sonucu şöyle olacaktır:
rect
circle
circle
❮ Harita Nesnesi