Select length Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select


The length property returns the number of <option> elements in a drop-down list.

Return Value

A Number, representing the number of <option> elements found in the drop-down list

The following code shows how to return the number of <option> elements found in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<select id="mySelect">
</select>//w w  w  . ja  v  a  2 s . c  om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("mySelect").length;
    document.getElementById("demo").innerHTML = x;


Related Tutorials