JSFiddle - React, Tailwind, and code Playground

by Muthuraman B

HTML

<input id="disableExample" type="button" value="disable all elements">
<div id="example">
  <input type="text" name="ex1">
  <input type="text" name="ex2">
  <input type="text" name="ex3">
</div>

JavaScript

function disableInputs(el) {
  var el = document.getElementById('example');
  var all = el.getElementsByTagName('input');
  var length = all.length;

  for (i = 0; i < length; i++) {    
    if(length > 0){
      all[i].disabled = true;
    }
  }
  
  
}
document.getElementById('disableExample').onclick = function () {
  disableInputs('example');
}