Reputation: 26281
Why doesn't the following work? How do I click an element, hide it for a bit, and then show it? http://jsfiddle.net/ba8bJ/
$('#myButton').click(function() {$(this).hide().delay(800).show()});
Upvotes: 1
Views: 299
Reputation: 103355
Pass a duration to show() and hide() because when a duration is provided, .show()
becomes an animation method.:
$('#myButton').on('click', function() {
$(this).hide(0).delay(800).show(0);
});
Upvotes: 1
Reputation: 262919
hide()
and show()
only use the animation queue if a duration is specified.
You can provide a duration of 0
and simply write:
$("#myButton").click(function() {
$(this).hide(0).delay(800).show(0);
});
You will find an updated fiddle here.
Upvotes: 3
Reputation: 10994
$('#myButton').click(function () {
$(this).fadeOut(0).delay(800).fadeIn(0)
});
Delay only works for animations/queried functions
Upvotes: 2
Reputation: 27012
Generally speaking, delay()
is for animations. Use setTimeout()
instead:
$('#myButton').click(function () {
var $this = $(this).hide();
setTimeout(function() {
$this.show();
}, 800);
});
Upvotes: 2