views:

395

answers:

5

Hi

i need to make a div text disappear after x seconds of displaying it using an ajax call

can you help me on this please ?

thanks

A: 

You would need to set something like setTimeout('$("#id").fadeOut("slow")', 5000) but other than that it depends on what the rest of your code looks like

jarrett
+1  A: 
$.doTimeout( 5000, function(){ 

 // hide the div
});
jball
+6  A: 

You can use empty() to remove a <div> contents:

setTimeout(fade_out, 5000);

function fade_out() {
  $("#mydiv").fadeOut().empty();
}

assuming:

<div id="mydiv">
  ...
</div>

You can do this with an anonymous function if you prefer:

setTimeout(function() {
  $("#mydiv").fadeOut().empty();
}, 5000);

or even:

var fade_out = function() {
  $("#mydiv").fadeOut().empty();
}

setTimeout(fade_out, 5000);

The latter is sometimes preferred because it pollutes the global namespace less.

cletus
working fine BUT i cannot recall that div again .. i need to remove the div content text while keeping the div itself for new use ... thanks
NetCaster
then remove the call to empty() and just do the fadeOut()
Bert Lamb
perfect .. many thanks
NetCaster
A: 

This should work:

$(document).ready(function() { 
    $.doTimeout(5000, function() { 
        $('#mydiv').fadeOut(); 
    }); 
});
Sander Rijken
What's the deal with $.doTimeout? Is that from a plugin, or part of the core?
ScottE
See http://benalman.com/projects/jquery-dotimeout-plugin/, in this case I'd just use window.setTimeout thought, not really worth the cost of a plugin for something this simple
Sander Rijken
A: 

my dropdown menu is getting hidden by the image which i am fading out pls check http://www.softsystest.com//speed_impax_25_03/html/promotions.html pls help

Kunal