HTML DOM दस्तावेज़ छवियां
उदाहरण
दस्तावेज़ में <img> तत्वों की संख्या:
document.images.length;
सभी <img> तत्वों पर लूप करें, और प्रत्येक का URL (src) आउटपुट करें:
const myImages = document.images;
let text = "";
for (let i = 0; i < myImages.length; i++) {
text += myImages[i].src + "<br>";
}
पहले <img> तत्व का URL है:
document.images[0].src;
पहले <img> तत्व का URL है:
document.images.item(0).src;
नीचे और अधिक उदाहरण।
परिभाषा और उपयोग
images
संपत्ति एक दस्तावेज़ में सभी <img> तत्वों का संग्रह लौटाती है ।
images
संपत्ति एक HTMLCollection देता है ।
images
संपत्ति केवल पढ़ने के लिए है ।
ध्यान दें
images
संपत्ति प्रकार = "छवि" के साथ <इनपुट> तत्व वापस नहीं करती है ।
यह सभी देखें:
HTMLसंग्रह
एक HTMLCollection HTML नोड्स का एक संग्रह है।
संग्रह में नोड्स को इंडेक्स नंबरों द्वारा एक्सेस किया जा सकता है। सूचकांक 0 से शुरू होता है।
लंबाई संपत्ति संग्रह में तत्वों की संख्या लौटाती है।
वाक्य - विन्यास
document.images
गुण
Property | Description |
length | The number of <img> elements in the collection. |
तरीकों
Method | Description |
[index] | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
item(index) | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
namedItem(id) | Returns the element with the specified id. Returns null if the id does not exist. |
प्रतिलाभ की मात्रा
प्रकार | विवरण |
वस्तु | एक HTMLCollection ऑब्जेक्ट। दस्तावेज़ में सभी <img> तत्व। तत्वों को सॉर्ट किया जाता है जैसे वे दस्तावेज़ में दिखाई देते हैं। |
और ज्यादा उदाहरण
id="myImg" के साथ <img> तत्व का URL है:
document.images.namedItem("myImg").src;
पहले <img> तत्व में एक काला बॉर्डर जोड़ें:
document.images[0].style.border = "10px dotted black";
ब्राउज़र समर्थन
document.images
एक डोम लेवल 1 (1998) फीचर है।
यह सभी ब्राउज़रों में पूरी तरह से समर्थित है:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |