0

How can I add a class when writing a value inside the input? Add class=active when input is not empty. My form has multiple inputs with class=outLjs, and I need to add a new class=active when the user writes a value inside the input, separately for each individual input.

let element = document.querySelectorAll(".outLjs");
for (var i = 0; i < element.length; i++) {
  element[i].addEventListener("input", (e)=>{
    if(e.data != null ) {
      element[i].classList.add("active"); 
    }else{
      element[i].classList.remove("active"); 
    }
  });

0 Answers0