Button disabled attribute

Definition and Usage

disabled Property sets or returns whether the button is disabled.

Disabled elements are not available and cannot be clicked. By default, disabled elements are usually displayed as gray in the browser.

This attribute reflects HTML disabled attribute.

Instance

Example 1

Disable the button:

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

Try it yourself

Example 2

Check if the button is disabled:

var x = document.getElementById("myBtn").disabled;

Try it yourself

Example 3

Disable and enable the button:

function disableBtn() {
    document.getElementById("myBtn").disabled = true;
}
function enableBtn() {
    document.getElementById("myBtn").disabled = false;
}

Try it yourself

Syntax

Return the disabled attribute:

buttonObject.disabled

Set the disabled attribute:

buttonObject.disabled = true|false

Attribute Value

Value Description
true|false

Specifies whether the button should be disabled.

  • true - The button is disabled
  • false - Default. The button is not disabled

Technical Details

Return Value: Boolean value, returns true if the button is disabled, otherwise returns false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <button> disabled Attribute