Button disabled Property
Example
Disable a button:
document.getElementById("myBtn").disabled = true;
The result will be:
Try it yourself »
Definition and Usage
The disabled property sets or returns whether a button is disabled, or not.
A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in browsers.
This property reflects the HTML disabled attribute.
Browser Support
The disabled property is supported in all major browsers.
Syntax
Return the disabled property:
buttonObject.disabled
Set the disabled property:
buttonObject.disabled=true|false
Property Values
Value | Description |
---|---|
true|false |
Specifies whether a button should be disabled or not
|
Technical Details
Return Value: | A Boolean, returns true if the button is disabled, otherwise it returns false |
---|
More Examples
Example
Find out if a button is disabled or not:
var x = document.getElementById("myBtn").disabled;
The result of x will be:
true
Try it yourself »
Example
Disable and undisable a button:
function disableBtn() {
document.getElementById("myBtn").disabled = true;
}
function undisableBtn() {
document.getElementById("myBtn").disabled = false;
}
Try it yourself »
Related Pages
HTML reference: HTML <button> disabled attribute
Button Object