tags:

views:

31

answers:

6

Hey All,

How can I make a <h3> fade out or just hide itself on my page after a few seconds once the page has loaded?

+2  A: 

You can use a simple .delay() call, like this:

$(function() {
  $("h3").delay(3000).fadeOut();
});

On document.ready this selects all <h3> elements and adds a 3 second delay before their .fadeOut(), just adjust the selector as needed, for example: h3.message for a
<h3 class="message">.

Here's the more general non-.delay() version of delaying any action:

$(function() {
  setTimeout(function() { $("h3").fadeOut(); }, 3000);
});
Nick Craver
:O - Thanks Nick!
lucifer
A: 
$(function(){$("whateverselector").fadeOut()});
joni
A: 
  $(document).ready(function() {
    setTimeout(function(){    $("#h3").fadeOut();    }, 3000);    
});
netadictos
A: 

There are different Timer Plugins for jQuery. Here is a short example. Here

Its possible to set a timer and if the time is over you hide or fadeout.

Stony
There's no need for plugins here, always look at what the core library has to offer first: http://api.jquery.com/ For that matter, look at what's in vanilla JavaScript before doing that.
Nick Craver
A: 

You can achieve this with setTimeout function: http://www.w3schools.com/js/js_timing.asp

var timeout = 3; // 3 seconds
$(function(){ // DOM ready
  setTimeout(function(){
    $("h3").fadeOut();
  }, timeout*1000);
});
Anpher
A: 

Hi!

Try the following:

$(function(){
setTimeout("$('h3.classname').fadeOut()", 2000);
});

This will make the h3 with class classname fade out 2 seconds after the DOM is loaded.

Ole Melhus
Never pass a string to `setTimeout()` if it can be avoided, use an anonymous function.
Nick Craver