Disable a button after clicking - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Disable a button after clicking

Demo Code

ResultView the demo in separate window

<html>
   <head>
      <script>
    function myFunction() {// w ww .j  a v  a2s .c  o  m
      var b = document.getElementById('result');
      b.innerHTML = 'You pressed the button.';
      document.getElementById('button1').disabled = 'disabled';
      return;
    }
  
      </script> 
   </head>
   <body> 
      <button onclick="myFunction()" id="button1">Press this</button> 
      <div id="result">
         You haven't pressed the button yet.
      </div>  
   </body>
</html>

Related Tutorials