I'm trying to show a div thats set to display: none;
for 5 seconds with
$('#div').show().delay(5000).hide();
but it deson't work, it just goes straight to hide()
Can any of you help me?
querySelector() and querySelectorAll() are two jQuery functions which helps the HTML elements to be passed as a parameter by using CSS selectors ('id', 'class') can be selected. querySelector() Method: The querySelector() method returns the first element within the document which matches a specified CSS selector(s).
ID and Element selector are the fastest selectors in jQuery.
In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery.
<p>This is a paragraph selected by a jQuery method. </p> <p>This is also a paragraph selected by a jQuery method. </p> $("p").
Do it like this:
$('#div').show(0).delay(5000).hide(0);
By passing in numbers to .show()
and .hide()
, jQuery will take those methods into its internal fx queue (even if the number is zero). Since .delay()
only works within a queue, you need that little workaround.
example: http://jsfiddle.net/zceKN/
You need to use .queue()
because .hide()
isn't queued by default.
$("#div").show().delay(5000).queue(function (next) {
$(this).hide();
next();
});
You need a duration on your hide for it to work:
$('#div').show('slow').delay(5000).hide('slow');
Example: http://jsfiddle.net/Paulpro/GLTaB/
$('#div').show();
setTimeout(function(){$('#div').hide();}, 5000);
.delay() works for animations only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With