Nancy Nancy - 1 year ago 40
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 Source

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

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

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