HTML DOM Select size Property


The HTML DOM select size property returns and modify the value of the size attribute of a drop-down list.

Syntax

Following is the syntax −

  • Returning size

object.size
  • Modifying value

object.size = “number”

Example

Let us see an example of HTML DOM select size property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   html{
      height:100%;
   }
   body{
      text-align:center;
      color:#fff;
      background: radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129,125,254,1) 0%, rgba(111,167,254,1) 90% ) no-repeat;
      height:100%;
   }
   p{
      font-weight:700;
      font-size:1.1rem;
   }
   .drop-down{
      display:block;
      width:35%;
      border:2px solid #fff;
      font-weight:bold;
      padding:2px;
      margin:1rem auto;
      outline:none;
   }
   .btn{
      background:orange;
      border:none;
      height:2rem;
      border-radius:2px;
      width:35%;
      margin:2rem auto;
      display:block;
      color:#fff;
      font-weight:bold;
      outline:none;
      cursor:pointer;
   }
   .show{
      font-size:1.5rem;
      font-weight:bold;
   }
</style>
</head>
<body>
<h1>DOM Select size property Demo</h1>
<p>Hi, Select your favourite subject:</p>
<select class='drop-down' name="Drop Down List">
<option>Physics</option>
<option>Maths</option>
<option>Chemistry</option>
<option>English</option>
<option>Economics</option>
<option>Hindi</option>
<option>Biology</option>
</select>
<button type="button" onclick="changeSize()" class="btn">Change Size</button>
<div class="show"></div>
<script>
   function changeSize() {
      var dropDown = document.querySelector(".drop-down");
      document.querySelector(".show").innerHTML="Size changed";
      dropDown.size="3";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Change Size” button to change the size of the drop-down list.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 01-Jul-2020

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements