Nancy Nancy - 4 months ago 6
Javascript Question

How to display message for 3 seconds in javascript

setTimeout(function(){
document.getElementById("alarmmsg").innerHTML=msg;
},3000);


Above code is displaying message but not going off screen. What could be the problem?

Answer

First display the message, then after 3 seconds delete it.

document.getElementById("alarmmsg").innerHTML = msg;

setTimeout(function(){
    document.getElementById("alarmmsg").innerHTML = '';
}, 3000);
Comments