DOM HTML Collection
Die HTMLCollection Object
'n HTMLCollection-objek is 'n skikking-agtige lys van HTML-elemente.
Metodes soos die getElementsByTagName() gee 'n HTMLCollection terug.
Eienskappe en metodes
Die volgende eienskappe en metodes kan op 'n HTMLCollection-objek gebruik word:
Property / Method | Description |
---|---|
item() | Returns the element at the specified index in an HTMLCollection |
length | Returns the number of elements in an HTMLCollection |
namedItem() | Returns the element with the specified ID, or name, in an HTMLCollection |
Voorbeelde
Voorbeeld
Kry 'n HTML-versameling:
var x = document.getElementsByTagName("P");
// Returns a
collection of all the P elements in the document
Voorbeeld
Skryf die aantal <p> elemente in die dokument:
var x = document.getElementsByTagName("P");
document.write(x.length);
Voorbeeld
Loop deur elke element in 'n HTML-versameling:
x = document.getElementsByTagName("*");
l = x.length;
for (i = 0; i <
l; i++) {
document.write(x[i].tagName + "<br>");
}