I have several elements with the className "error", I need to dynamically add a unique id to each one. From other questions on stack I have put together the following code but it doesn't seem to work.
function setErrorId() {
var errorClass = document.getElementsByClassName('error');
for (i = 0; i < errorClass.length; i++) {
var idName = 'error' + i;
errorClass[i].id = idName;
}
}iis an undefined variable