How to Call a Function After Some Time in jQuery
In this tutorial, we are going to see how to call a function after some time in jQuery. You can simply use jQuery’s delay() method to set the delay time interval. Here is an example:
How to Call a Function After Some Time in jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>How to Call a Function After Some Time</title>
<style type="text/css">
.box{
display: none;
width: 300px;
border: 15px solid green;
padding: 50px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
function showBox(){
$("div.box").fadeIn(600);
}
$(document).ready(function(){
$(".show-box").click(function(){
$(this).text('loading...').delay(1000).queue(function() {
$(this).hide();
showBox();
$(this).dequeue();
});
});
});
</script>
</head>
<body>
<button type="button" class="show-box">Show Box</button>
<div class="box"></div>
</body>
</html>
| Result |
|---|




