Before I call:
$('myObject').show();
I want to know if it is currently hidden or visible.
To check if an element is hidden or not, jQuery :hidden selector can be used. .toggle() function is used to toggle the visibility of an element.
$(selector).hide(speed,callback); $(selector).show(speed,callback); The optional speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", or milliseconds.
jQuery hide() Method The hide() method hides the selected elements.
If you want to check visibility instead of display, you should use: . css("visibility") == "hidden" .
There's 2 ways to do it, that I know of:
if ($('#something').is(':hidden')) { }
or
if ($('#something').is(':visible')) { }
They should both work.
You can also do something like this:
$('#something:hidden').show();
$('#something:visible').hide();
Which will only call .show() if the item is already hidden, or only call .hide() if the item is already visible.
You could also use the Toggle $(this).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