Is this proper code for javascript?
var inputsClass = document.getElementsByClassName("inputClass");
var errorSpan = document.getElementsByClassName("errorSpan");
for(var index=0; index < inputsClass.length;index++ ){
inputsClass[index].onclick=function(){
inputsClass[index].errorSpan.style.color="black";
}
}
Because in my JavaScript console it says Uncaught TypeError: Cannot read property 'style' of undefined
But I have an equal amount of tags that have the class inputsClass
and errorSpan
. Yet inputsClass[index]
seems undefined.
HTML Portion
<h1> SIGN UP </h1>
<br />
<input type="text" name="firstName" placeholder="First Name"
class="inputClass" autofocus/>
<span class="errorSpan"> Testing... </span>
<br />
<input type="text" name="lastName" placeholder="Last Name" class="inputClass"/>
<span class="errorSpan"> Testing... </span>
<br />
<input type="text" name="userName" placeholder="Username" class="inputClass"/>
<span class="errorSpan"> Testing... </span>
<br />
<input type="password" name="password" placeholder="Password" class="inputClass"/>
<span class="errorSpan"> Testing... </span>
<br />
<input type="password" name="retypePassword" placeholder="Retype Password"
class="inputClass"/>
<span class="errorSpan"> Testing... </span>
<br />
<input type="email" name="email" placeholder="Email" class="inputClass"/>
<span class="errorSpan"> Testing... </span>
<br />
So the testing text node should turn black when the input tags are clicked on. By the way, I really appreciate you helping me out jfriend00