I want to do the below with pure JavaScript if it is possible (or jQuery)
- the page is fully loaded.
- wait 5 seconds.
- alert('msg') once with no setInterval loops.
I want to do the below with pure JavaScript if it is possible (or jQuery)
- the page is fully loaded.
- wait 5 seconds.
- alert('msg') once with no setInterval loops.
- 2 The downvotes are a result of lack of research effort as this shouldn't be hard to research yourself and at least e up with a code attempt – charlietfl Commented Apr 26, 2015 at 14:52
3 Answers
Reset to default 3Try setTimeout
:
document.onload = setTimeout(function () { alert('msg'); }, 5000);
jQuery solution:
$(document).ready(function()
{
setTimeout(function()
{
alert('msg');
},
5000);
});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Use setTimeout
, not setInterval
. I kept the answer as verbose as the question.
Try this:
$(document).ready(function(){
setTimeout(function(){ alert("msg");}, 5000)
})
do not forget put jquery reference to your html header:
<script src="http://code.jquery./jquery-2.1.3.min.js"></script>