Javascript DOM HTML Option disabled Property get

Introduction

Find out if the second option (index 1) in a drop-down list is disabled:

var x = document.getElementById("pets").options[1].disabled;

Click the button to find out if the second option in the dropdown list is disabled.

View in separate window

<!DOCTYPE html>
<html>
<body>

<select id="pets" size="3">
  <option>CSS</option>
  <option disabled>Java</option>
  <option>HTML</option>
</select>// w  w  w .  j  a  v  a 2 s. c  o  m

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

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

<script>
function myFunction() {
  var x = document.getElementById("pets").options[1].disabled;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related