How to Disable a Button using JavaScript?

To disable or enable a button in JavaScript we can use the disabled property. If the disabled property is set to true, the button becomes disabled and if it is set to false, the button becomes enabled.

A disabled button is not clickable by the user and it is generally rendered in grey color for most of the browsers by default.

See the following working example:


var myBtn = document.getElementById('myBtn');

function disableBtn(){
    myBtn.disabled = true;  // Disabled

function enableBtn(){
    myBtn.disabled = false;  // Enabled