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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With