Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

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("txtHint").innerHTML="Hello" Here, the message "hello", I want it to disappear after  3 seconds. Thanks!  

<div id="txtHint"></div>
ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Thank you Prakash, now its working!
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>

Open in new window

welcome :)
HTML

<button onclick="Go()">Show</button>

<div id="txtHint">MyHint</div>

Open in new window


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);
}

Open in new window