Javascript DOM HTML Select size Property set

Introduction

Change the number of visible options in a drop-down list:

document.getElementById("mySelect").size = "4";

Click the button to change the number of visible options in the dropdown list.

View in separate window

<!DOCTYPE html>
<html>
<body>

<select id="mySelect" size="1">
  <option>CSS</option>
  <option>Java</option>
  <option>HTML</option>
  <option>SQL</option>
  <option>Mouse</option>
  <option>Fish</option>
  <option>Cow</option>
</select>//from w  w  w .  ja va 2 s  .  c om
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
   document.getElementById("mySelect").size = "4";
}
</script>

</body>
</html>

The size property sets or gets the value of the size attribute of a drop-down list.

The size attribute sets the number of visible options in a drop-down list.

The size property accepts and returns a number type value.




PreviousNext

Related