Computer >> Computer tutorials >  >> Programming >> HTML

HTML DOM Input Button disabled Property


The HTML DOM input button disabled property returns and alter the value of disabled attribute of an input button in HTML.

Syntax

Following is the syntax −

1. Returning name

object.disabled

2. Modifying name

object.disabled = true|false

Example

Let us see an example of disabled property −

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM disabled Property</title>
<style>
   body{
      text-align:center;
   }
   .btn{
      display:block;
      margin:1rem auto;
      background-color:#db133a;
      color:#fff;
      border:1px solid #db133a;
      padding:0.5rem;
      border-radius:50px;
      width:80%;
   }
   .show-message{
      font-weight:bold;
      font-size:1.4rem;
      color:#ffc107;
   }
</style>
</head>
<body>
<h1>disabled Property Example</h1>
<input type="button" onclick="disableMe()" class="btn" value="Click me to Disable me">
<div class="show-message"></div>
<script>
   function disableMe() {
      var btn= document.querySelector(".btn");
      btn.disabled = true;
      document.querySelector(".show-message").innerHTML="Previously I'm enabled but now I'm disabled";
   }
</script>
</body>
</html>

Output

This will produce the following output −

HTML DOM Input Button disabled PropertyNow, click on “Click me to Disable me” button to disabled red button.

HTML DOM Input Button disabled Property