Javascript DOM HTML OptionGroup disabled Property set

Introduction

Disable an option-group:

document.getElementById("myOptgroup").disabled = true;

Click the button to disable some options in the dropdown list.

View in separate window

<!DOCTYPE html>
<html>
<body>

<select size="6">
  <option value="CSS">CSS</option>
  <option value="c++">C++</option>
  <optgroup id="myOptgroup" label="Programming Language">
    <option value="javascript">Javascript</option>
    <option value="html">HTML</option>
    <option value=""sql">SQL</option>
  </optgroup>
</select>/*from w ww. j a  va 2 s .  c  o  m*/

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

<script>
function myFunction() {
  document.getElementById("myOptgroup").disabled = true;
}
</script>

</body>
</html>

The disabled property sets or gets whether an option-group is disabled.

The disabled property accepts and returns a boolean value.

Value Description
trueThe option-group is disabled
false Default. The option-group is not disabled

The disabled property returns true if the option-group is disabled, otherwise it returns false




PreviousNext

Related