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


  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts