javascript - Click button show div and hide same div after 5 seconds -
i have email submitting form , when user submits, show confirmation text below input. after 5 seconds confirmation text has fade-out again.
this code
<div class="input-group newsletter-group"> <input type="text" class="form-control" id="email-to-submit"> <div id="submit-email" class="input-group-addon">go!</div> </div> <div id="email-submit-form">thanks!</div> <div id="invalid-email-warning" style="color: red; display: none;">not email address</div> $(function() { settimeout(function() { $("#email-submit-form").fadeout(1500); }, 5000) $('#submit-email').click(function() { var emailaddress = $('#email-to-submit').val(); if (validateemail(emailaddress)){ $('#email-to-submit').val(''); $('#email-submit-form'); $.ajax({ type: "post", url: '/submitemailaddress', datatype: 'json', data: json.stringify({'email': emailaddress}) }); } else { $('#invalid-email-warning').show(); } $('#email-submit-form').show(); settimeout(function() { $("#email-submit-form").fadeout(1500); }, 5000) }) });
you can use jquery delay()
$('#email-submit-form').fadein().delay(5000).fadeout();
Comments
Post a Comment