How to Disable and Enable HTML Inputs, Buttons or Textareas

 HTML inputs, buttons and textareas have the "disanled" attributes. if you want to set them to be disabled, you can put the "disabled" attribute in the html tags such as 

<button disabled>button</button>
<input disabled>
<textarea disabled>></textarea>

What if we want to disable the above elements?

We can use the following code.
<button id = "demobutton">button</button>
<button onclick="demobutton.disabled = false">enable button</button>
<script>
    demobutton.disabled = true;
</script>

Interesting Facts

  1. You can use somebutton.setAttribute("disabled","true"), but you can't use somebutton.setAttribute("disabled","false"), because the 'disabled' attribute is not defined by disabeld = "true" or "false". 
  2. If the "disabled" attribute is there, it will be disabled, regardless the value to be true or false.


Comments

Popular posts from this blog

How to Make A Reusable Image Slideshow HTML Component With Vanilla JavaScript

HTML Tags and Inline CSS that Work In Plotly.js Title

How to Type Spaces In HTML Input And Display In the Browser