February 27, 2013

jQuery fade-out DIV display after certain set time

Question by Dan

I have the following code and would like to hide a DIV (.video-field-new) after a specified amount of time after the page loads, for example 5 seconds. Is that possible?

<div id="BodyField">
    <div class="video-field-new"></div>
</div>

And bonus if I could have it fade-out instead of just disappearing as the user will see this occurring.

Answer by dystroy

$(window).load(function(){
  setTimeout(function(){ $('.video-field-new').fadeOut() }, 5000);
});

Answer by Starx

You can do it in this way

$("#BodyField").delay(5000).fadeOut();

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!