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'),
      all = el.getElementsByTagName('input'),
      i;
      
      var length = all.length;
      
  for (i = 0; i < length; i++) {
    
    if(length > 4){
    	all[i].disabled = true;
    }else {
    
    }
    
  }
}
document.getElementById('disableExample').onclick = function () {
  disableInputs('example');
}