Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Show modal after every 5 seconds without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I want my modal to show as a popup after every 5 seconds without triggering the button, but I am unable to do it. I used jquery function show and setTimeout but it works only the first time the page is loaded
This is my jquery:
<script> $(document).ready(function(){ setTimeout(function(){ $('#myModal').modal('show'); }, 2000); }); </script>
My Modal:
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <p>Some text in the modal.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
I want it to open after every 5 seconds Please help
Answer
Try this
setInterval(function () { $('#myModal').modal('show'); }, 5000);
The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
We are here to answer your question about Show modal after every 5 seconds - If you find the proper solution, please don't forgot to share this with your team members.