HTML DOM
The length property of the HTMLSelectElement interface specifies the number of option elements in the select element. It represents the number of nodes in the HTMLSelectElement.options collection. On setting, it acts as (HTMLOptionsCollection.length).
Value
A number.
Examples
const selectElement = document.getElementById("fruits");
console.log(selectElement.length);
Specifications
Browser compatibility
See also
- select
- option
- HTMLSelectElement.options
- HTMLSelectElement.selectedOptions
- HTMLSelectElement.multiple
- HTMLSelectElement.selectedIndex
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
