By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

How do I hide the modal after 5 seconds?

I’ve tried the code below but it doesn’t seem to work well. Please help!!! I’m trying to get the modal to popup with an onclick event as it normally would but then I want it to disappear after about 5 seconds and hide the ability to allow the user from making it hide.

<html xmlns="http://www.w3.org/1999/xhtml">
<title>jQuery Hide DIV Elements after 10 seconds</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
setTimeout(function() { $("#testdiv").fadeOut(1500); }, 5000)
$('#btnclick').click(function() {
setTimeout(function() { $("#testdiv").fadeOut(1500); }, 5000)
<style type="text/css">
border: 2px solid Red;
color: #008000;
padding: 10px;
width: 400px;
<input type="button" id="btnclick" value="Show DIV" />
<div class="content" id="testdiv" class="">
Hi, Welcome to Aspdotnet-Suresh.com
It will disappear in 4 seconds!
N.B. I did add $('#testdiv').hide(); at the start of the self executing function, as I think you wanted to see the div only hen you click the button.
Top Bottom