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 βˆ’

 Live Demo

<!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 βˆ’

Now, click on β€œClick me to Disable me” button to disabled red button.

Updated on: 2019-07-30T22:30:26+05:30

159 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements