Javascript Reference - HTML DOM Input Color disabled Property








The disabled property disable or enable a color picker.

Browser Support

disabled Yes No Yes No Yes

Syntax

Return the disabled property.

var v = colorObject.disabled 

Set the disabled property.

colorObject.disabled=true|false

Property Values

Value Description
true|false Disable or enable a color picker
  • true - The color picker is disabled
  • false - Default. The color picker is not disabled




Return Value

A Boolean type value, true if the color picker is disabled, otherwise it returns false.

Example

The following code shows how to get if a color picker is disabled.


<!DOCTYPE html>
<html>
<body>
<input type="color" id="myColor" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--  ww w  .ja va  2s  .  c om-->
<script>
function myFunction() {
    var x = document.getElementById("myColor").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to use disable and enabled a color picker.


<!DOCTYPE html>
<html>
<body>
<!--   w ww  .j a  v  a2  s . co m-->
<input type="color" id="myColor"><br><br>

<button onclick="disableBtn()">Disable Color Picker</button>
<button onclick="enableBtn()">Enable Color Picker</button>

<script>
function disableBtn() {
    document.getElementById("myColor").disabled = true;
}
function enableBtn() {
    document.getElementById("myColor").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: