I've got a simple login form with email and password I have this code to validate the email
$(document).ready(function() {
$('#login-submit').click(function() {
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $(".email").val();
if(emailaddressVal == '') {
$(".email").after('<span class="error">Please enter your email address.</span>');
hasError = true;
}
else if(!emailReg.test(emailaddressVal)) {
$(".email").after('<span class="error">Enter a valid email address.</span>');
hasError = true;
}
if(hasError == true) { return false; }
});
});
the span with the class of .error (as per the design I've got) hides the input element.
I want to hide the error message again when I click it
$(document).ready(function() {
$('.error').click(function() {
$(".error").remove();
});
});
but this does nothing. Anyone know what I'm doing wrong here?