I created a form with several inputs, one of them is "Full Name",and of course a submit button at the end.
function checks if the name input is alphabetical characters only, if true, it will append the div element , add the css class, snackbar will fade in and out, and finally disappear. what is wrong with the following code:
$(document).ready(function(){
$(".submitForm").click(function(){
var fullname = $("#firstName").value;
var checkIfTrue = /^[A-Za-z ]+$/.test(fullname);
if (checkIfTrue==true) {
$('body').append("<div id='textBox'> some text</div>");
$("#textBox").addClass("showPopup");
setTimeout(function(){
$("#textBox").remove();}, 3000);
return true;
}
else {
alert("wrong input");
return false;
}
})
})
and there is the relevant css:
.showPopup {
visibility : visible;
animation : fadein 0.5s, fadeout 0.5s 2.5s;
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 20px; opacity: 1;}
}
@keyframes fadeout {
from {bottom: 20px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
cheers (couldn't figure it out myself with : jQuery: append() object, remove() it with delay() )