I have a form with lots of input elements and there's nothing telling the user which fields are required. The problem is that I don't have access to its HTML code.
So I'm writing this JavaScript:
var allInputs = document.querySelectorAll("input");
var newItem = document.createElement("LI");
var textnode = document.createTextNode("(*)");
newItem.appendChild(textnode);
for (var i = 0; i < allInputs.length; i++) {
if(allInputs[i].hasAttribute('required') == true){
allInputs[i].parentNode.insertBefore(newItem, allInputs[i]);
}
}
Result: it adds (*) before the last input only. I've tried running this code on the browser console line by line, and I've noticed that it adds the text on a input and erases the previous one.
I'm not a web developer and I'm using examples I found on the internet, so this is tricky for me :/