Latest web development tutorials

HTML DOM Select length property

Select Object Reference Select Objects

Definition and Usage

The length property returns the number of drop-down list of options.

grammar

selectObject.length=number


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support length property


Examples

Examples

Displays the number of drop-down list of options:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    alert(document.getElementById("mySelect").length);
}
</script>
</head>
<body>

<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">下拉列表中有多少选项?</button>

</body>
</html>

try it"


Select Object Reference Select Objects