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>
Whing Dela CruzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prakash SamariyaIT ProfessionalCommented:
Use below javascript code for it
<script> setTimeout(function(){ document.getElementById("txtHint").innerHTML="" }, 3000);</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Whing Dela CruzAuthor Commented:
Thank you Prakash, now its working!
0
Prakash SamariyaIT ProfessionalCommented:
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

0
Prakash SamariyaIT ProfessionalCommented:
welcome :)
0
Leonidas DosasCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
div

From novice to tech pro — start learning today.