Link to home
Start Free TrialLog in
Avatar of NGTLD
NGTLD

asked on

Javascript display image for 5 seconds and then hide

Title says it all, I want to display an image for 5 seconds and then have it disappear. I have some banner rotation scripts, but I just want this to show up once.
Avatar of Tony O'Byrne
Tony O'Byrne
Flag of United States of America image

Use some Javascript for this.

First, give the image an id...  <img id="imgToHide"... />

Then set a function to start when the body loads...

<body onload="javascript:hideImage()">

And the function is below:
function hideImage(){
    //  5000 = 5 seconds
    setTimeout( 5000, doHide ) ;
}

function doHide(){
    document.getElementById( "imgToHide" ).style.display = "none" ;
}

Open in new window

Avatar of NGTLD
NGTLD

ASKER

not sure why, but it is not working for me
My bad - I got the timeout arguments mixed up and forgot some quotes...
<script>
	function doHide(){
		document.getElementById( "imgToHide" ).style.display = "none" ;
	}

	function hideImage(){
		//  5000 = 5 seconds
		setTimeout( "doHide()", 5000 ) ;
	}
</script>

Open in new window

please post your code.
Avatar of NGTLD

ASKER

Still nothing
Avatar of NGTLD

ASKER

I am using the code posted above
\
ASKER CERTIFIED SOLUTION
Avatar of Tony O'Byrne
Tony O'Byrne
Flag of United States of America 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
If that doesn't work, then change the above code to include your image by putting your image inside the <div> </div> tags and see if that helps.


If that doesn't work, check that you have Javascript enabled. :)
Avatar of NGTLD

ASKER

THat did it thanks
You're welcome. :)  Thanks for the points.