We help IT Professionals succeed at work.

Timer on div

Whing Dela Cruz
on
420 Views
Last Modified: 2017-04-02
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>
Comment
Watch Question

IT Professional
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thank you Prakash, now its working!
Prakash SamariyaIT Professional
CERTIFIED EXPERT
Top Expert 2015

Commented:
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

Prakash SamariyaIT Professional
CERTIFIED EXPERT
Top Expert 2015

Commented:
welcome :)
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions