I have a validation script that once submitted, will append error "li" tags to an empty div below the form. It works great though I would like to slide down this div once the "li" tags are appended to the div.
I have used the .slideDown effect from jQuery to accomplished this but it seems to only slide down to the first "li" tag, after that it jumps through the rest of the "li" tags. I can't figure out why, and the slide down effect is on the div itself not the "li" tags.
Here is a working example in my CodePen.
Here is the code:
$("form").on("submit", function(e){
$("li").remove();
$("input").each(function(){
var $this = $(this);
if($($this).val() === ""){
var formName = $($this).attr("name");
var errorMessage = $(".errorMessage");
var li = $("<li></li>",{
text: "There was an error with " + formName,
class: "errorText",
});
$($this).addClass("errorInput");
$(errorMessage).append(li);
$(errorMessage).slideDown(1500);
e.preventDefault();
} if($($this).val() != ""){
$($this).removeClass("errorInput");
} else{
return true;
}
}); //Input
}); //Form .submit