Reputation: 133
When a page loads, a div
should appear for like 3 seconds and then automatically disappear. I'm having trouble with the code at the moment. I'm using this code below:
jQuery("#infor").delay(6000).fadeOut("slow");
My HTML is:
<div id="infor">
something
</div>
But it doesn't seem to be working. Does anyone have any idea why this code is not working?
Upvotes: 3
Views: 9504
Reputation: 12717
Is your code within a document.ready
block?
$( document ).ready(function() {
$("#infor").delay(3000).fadeOut("slow");
});
It works for me: http://jsfiddle.net/YdU4z/
Upvotes: 6
Reputation: 76547
Your syntax appears to be correct (however if you wanted the delay to be for about 3 seconds, you should change the value inside the delay to 3000).
Do you have this code being wrapped within a document-ready block as seen below?
<script type='text/javascript'>
//Short-hand for $(document).ready()
$(function(){
//Delay for ~3 seconds and then fade out
$("#infor").delay(3000).fadeOut("slow");
});
</script>
I would try using the Developer Tools (F12) within your browser to see if any errors are being thrown (within the Console) and also ensure that the version of jQuery you are using supports the functions being called as well.
Upvotes: 2