Disable a button with setAttribute("disabled") and removeAttribute("disabled") - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Disable a button with setAttribute("disabled") and removeAttribute("disabled")

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <button id="btn1" onclick="disbtn(this.id);">button 1</button> 
      <script type="text/javascript">
function disbtn(id) {// w ww  . j a v  a2s .co  m
    if ( id == "btn1" ) {
       document.getElementById(id).setAttribute("disabled","disabled");
    } else {
       document.getElementById(id).removeAttribute("disabled");
    }
}

      </script>  
   </body>
</html>

Related Tutorials