Whing Dela Cruz
asked on
Timer on div
Hi experts, would it be possible to put timer on div? I have a div with an id, txtHint. then, I have this command document.getElementById("t xtHint").i nnerHTML=" Hello" Here, the message "hello", I want it to disappear after 3 seconds. Thanks!
<div id="txtHint"></div>
<div id="txtHint"></div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try with below code change
<script>
function Go(e)
{
var msg = "Hello!"
document.getElementById("txtHint").innerHTML=msg;
setTimeout(function(){ document.getElementById("txtHint").innerHTML="" }, 3000);
}
</script>
welcome :)
HTML
JS
<button onclick="Go()">Show</button>
<div id="txtHint">MyHint</div>
JS
//Initialy i set var with the div element
var divElm=document.getElementById('txtHint');
//I hide the divElm
divElm.style.display='none';
//I create a function that when it invokes the div logo appear
function Go()
{
var msg = "Hello!";
divElm.innerHTML=msg;
divElm.style.display='inline';
//I use the setTimeout to hide the divElm after 3 sec=3000ms
setTimeout(function(){
divElm.style.display='none';
}, 3000);
}
ASKER