Javascript Reference - HTML DOM OptionGroup disabled Property








The disabled property disables or enables an option-group.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

optiongroupObject.disabled 

Set the disabled property.

optiongroupObject.disabled=true|false 

Property Values

Value Description
true|false Enable or disable an option-group
  • true - The option-group is disabled
  • false - Default. The option-group is not disabled




Return Value

A Boolean type value, true if the option-group is disabled, otherwise false.

Example

The following code shows how to check if an option-group is disabled.


<!DOCTYPE html>
<html>
<body>
<!--from   w  w  w. j  ava2s.co  m-->
<select size="6">
  <option value="B">B</option>
  <option value="A">A</option>
  <optgroup id="myOptgroup" label="My Group" disabled>
    <option value="X">X</option>
    <option value="T">T</option>
  </optgroup>
</select>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myOptgroup").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to disable an option-group.


<!DOCTYPE html>
<html>
<body>
<!--   w  w w .ja v  a 2 s  . c o m-->
<select size="6">
  <option value="B">B</option>
  <option value="A">A</option>
  <optgroup id="myOptgroup" label="My Group" disabled>
    <option value="X">X</option>
    <option value="T">T</option>
  </optgroup>
</select>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myOptgroup").disabled = true;
}
</script>

</body>
</html>

The code above is rendered as follows: