I have an element that when clicked is either visible or hidden using jQuery's toggle() method.
Using toggle() is it possible to delay it from being hidden for a few seconds, while not delaying the visibility?
$('.myelement').click(function() {
$('.myelement').toggle();
});
Just try with:
$('.myelement').click(function() {
if ($(this).is(':visible')) {
$(this).delay(1000).hide();
} else {
$(this).show();
}
});
Or simplier:
$('.myelement').click(function() {
$(this).delay($(this).is(':visible') ? 1000 : 0).toggle();
});
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