The Select length property in HTML DOM is used to return the number of <option> elements in a drop-down list. This property returns an integer value on success else returns an error.
Syntax:
selectObject.length
Below program illustrates the Select length property in HTML DOM:
Example: This example returns the number of <option> elements found in a drop-down list.
<!DOCTYPE html> <html> <head> <title> HTML DOM Select length Property </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h2 style="font-family: Impact;"> Select length Property </h2> Select your preferred course from the drop-down list: <select id="myCourses"> <option value="C++">c++</option> <option value="Placement">Placement</option> <option value="Java">Java</option> <option value="Python">Python</option> </select> <p> To return the number of elements in the dropdown list, double-click the "Return Count" button. </p> <button ondblclick="myGeeks()"> Return Count </button> <p id="GFG"></p> <!-- Script to use Select length Property --> <script> function myGeeks() { var d = document.getElementById("myCourses").length; document.getElementById("GFG").innerHTML = d; } </script> </body> </html> |
Output:
Before Clicking the button:

After clicking the button:

Supported Browsers: The browser supported by DOM Select length Property are listed below:
- Apple Safari
- Internet Explorer
- Firefox
- Google Chrome
- Opera
Recommended Posts:
- HTML | DOM Select name Property
- HTML | DOM Select value Property
- HTML | DOM Select type Property
- HTML | DOM Select size Property
- HTML | DOM Select form Property
- HTML | DOM Select multiple Property
- HTML | DOM Select selectedIndex Property
- HTML | DOM Select autofocus Property
- HTML | DOM Select disabled Property
- HTML | DOM length Property
- HTML | DOM Form length Property
- HTML | DOM History length Property
- HTML | Window length Property
- HTML | DOM Storage length Property
- CSS | user-select Property
- How to select all elements that contains some specific CSS property using jQuery ?
- HTML | <select> Tag
- HTML | DOM Select add Method
- HTML | <select> name Attribute
- HTML | DOM Select Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


