I have form consists of 3 input fields and corresponding span classes beside them. I'm creating a validation with only using jquery/javascript no plugins. Is there a way where the span messages will appear if the user input invalid type of name, like if user input 123 on userName field the span that has message Invalid Username will appear? by only using classes not id's
<input type = 'text' class = 'inputs' id = 'userName'> <span class = 'messageSpan' id = 'userNameMessage'>Invalid Username</span><br><br>
<input type = 'text' class = 'inputs' id = 'phoneNumber'> <span class = 'messageSpan' id = 'phoneNumberMessage'> Invalid Phone Number </span><br><br>
<input type = 'text' class = 'inputs' id = 'emailAddress'><span class = 'messageSpan' id = 'emailAddressMessage'> Invalid Email</span><br><br>"
Here is my code
$(".messageSpan").hide();
$(".inputs")click(function(){
$(this).find('.messageSpan').show();
});
I have tried ung .each but it only shows all the spanMessages once I clicked one field, I want something to make the spanMessage appear only by clicking the corresponding textfield.