How do I optimize the following code, so that the output will assign an attribute to two input fields? I developed the following code, but it doesn't seem to work yet:
const addAttribute = document.querySelectorAll("#form-field-name, #form-field-escort");
for (let i=0; i<addAttribute.length; i++) {
addAttribute.setAttribute("onvalid","this.setCustomValidity('Bitte füllen Sie dieses Feld aus.');")
}
I am beginner, so please don't judge me for misunderstanding some code lines. Would really appreciate, if someone could explain to me what I did wrong and help optimize the code to make this working.