tags:

views:

531

answers:

3

i need to hide a div (like mail sent successfull in gmail)after certain time period when i reload the page ? any body please help me by giving codes..

+15  A: 

In older versions of jquery you'll have to do it the "javascript way" using settimeout

setTimeout( function(){$('div').hide();} , 4000);

or

setTimeout( "$('div').hide();", 4000);

Recently with jquery 1.4 this solution has been added:

$("div").delay(4000).hide();

Of course replace "div" by the correct element using a valid jquery selector and call the function when the document is ready.

marcgg
I don't think the first example will work ...
Pointy
@pointy, it should be fixed
marcgg
Reason being, the `setTimeout` function expects as it's first parameter either a function, or a string. You are providing neither, you are EXECUTING the function, and the return of that function is what you are sending to the `setTimeout` function. This will work if you pass the function itself, like this: `setTimeout( $( "#div" ).hide, 4000 );`.
Jacob Relkin
@jacob: edited my answer, I think the examples I give should work fine
marcgg
Not to mention that passing a string is way less efficient than passing a function because it causes the `exec` function to parse the function.
Jacob Relkin
<html ><head><title>Untitled Document</title><script type="text/javascript">$('#deletesuccess').delay(1000).fadeOut();</script></head><body><div id=deletesucess >hiiiiiiiiiii</div></body></html>i have tried this code but not working?pls tell wot is pblm for this code....
rag
@jacob true about the exec part. I doubt it would make a big difference in the end... because if we start like that we could argue that defining the function on the fly like that takes more bits and would be longer to load. I'd say perf are not an issue here, so it's up to the OP to use whatever syntax he likes more (even though i'd recommend using function()... )
marcgg
@rag - for one, you don't load jQuery there.
Kobi
@rag: call it on document ready
marcgg
@rag also you don't load jquery as @kobi mentionned
marcgg
<html><head><title>Untitled Document</title><script type="text/javascript" src="jquery-1.3.2.min.js"></script><script type="text/javascript">$('#deletesuccess').delay(1000).fadeOut();</script></head><body><div id=deletesucess >hiiiiiiiiiii</div></body></html>i have included kobi still it s not wrking..
rag
@rag You need jquery 1.4.2, not 1.3; please read my answer.
marcgg
@rag: You have a typo: `deletesuccess` in selector but `deletesucess` in id.
rosscj2533
i will try marcgg
rag
marcgg i hav tried it wit jquery 1.4.2 .........not working still..
rag
@rag: check your syntax, typos and so on. respect valid xhtml and so on, also
marcgg
Uncaught SyntaxError: Unexpected identifier /jqury/jquery-1.4.2.min.js:77timehidediv.php:8Uncaught ReferenceError: $ is not defined/ these are the new errors when i tried jquery 1.4.2
rag
u der marcgg? forgot me if am late..:)
rag
<html><head><title>Untitled Document</title><script type="text/javascript" src="jquery-1.4.2.min.js"></script><script type="text/javascript">$(document).ready(function(){$('#deletesucess').delay(1000).fadeOut();});//setTimeout('$("#deletesucess").hide()',1500);</script></head><body><div id="deletesucess" >hiiiiiiiiiii</div></body></html>tried it in document ready still failed...
rag
@ross and @marcgg, fyi, your dismal level of service (shame on you, no reaction for 20 minutes!!!) left the OP no choice but to ask *the same question again* : http://stackoverflow.com/questions/2426659/hiding-a-div-with-certain-time-bound
Pekka
@rag: you have a problem with your jquery if it doesn't even recognize $. Try downloading it again and please don't open duplicate questions. Check your div ids and so on.
marcgg
@rag looks like your jquery is broken, as @marc says download it again.
Pekka
+2  A: 
setTimeout('$("#someDivId").hide()',1500);
Jage
+2  A: 

Here's a complete working example based on your testing. Compare it to what you have currently to figure out where you are going wrong.

<html> 
  <head> 
    <title>Untitled Document</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
    <script type="text/javascript"> 
      $(document).ready( function() {
        $('#deletesuccess').delay(1000).fadeOut();
      });
    </script>
  </head> 
  <body> 
    <div id=deletesuccess > hiiiiiiiiiii </div> 
  </body> 
</html>
rosscj2533
thanks rosscj2533..........
rag