Javascript DOM HTML Button disabled Property set

Introduction

Disable a button:

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

Click the button below to disable the button above.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn">My Button</button>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w  ww .  java  2 s  .  co  m*/
  document.getElementById("myBtn").disabled = true;
}
</script>

</body>
</html>

The disabled property sets or gets whether a button is disabled.

This property mirrors the HTML disabled attribute.

Value Description
true The button is disabled
false Default. The button is not disabled

The disabled property returns true if the button is disabled, otherwise it returns false.




PreviousNext

Related