You can disable the
<button> element in HTML by adding the
disabled attribute to the element.
disabled attribute is a boolean attribute that allows you to disable an element, making the element unusable from the browser.
You just need to add the
disabled attribute without any value as shown below:
<button disabled>Click me</button>
disabled attribute is a boolean attribute, you don’t need to assign any value to it.
When you need to enable the
disabled property to
First, let’s add an
id attribute to the
<button id="disabled" disabled>Click me</button>
Now you can enable the button by using the
document.getElementById() method as follows:
document.getElementById("disabled").disabled = false;
You can also disable the button programmatically by setting the
disabled attribute to
document.getElementById("disabled").disabled = true;