HTMLOptionsCollection: length-Eigenschaft
Die length
-Eigenschaft des HTMLOptionsCollection
-Interfaces gibt die Anzahl der <option>
-Elemente in der Sammlung zurück. Die Eigenschaft kann die Größe der Sammlung abrufen oder festlegen.
Wenn length
auf einen Wert kleiner als der aktuelle gesetzt wird, wird die Optionssammlung gekürzt; andernfalls werden neue leere <option>
-Elemente am Ende des <select>
angehängt.
Wert
Ein ganzzahliger Wert, der die Anzahl der Elemente in dieser HTMLOptionsCollection
darstellt.
Beispiel
js
const optCollection = document.getElementById("fruits").options;
const origLength = optCollection.length;
optCollection.length += 50; // adds 50 blank options to the collection
optCollection.length = origLength; // truncates the list back to the original size
Spezifikationen
Specification |
---|
HTML # dom-htmloptionscollection-length-dev |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
length |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.