I am trying to find out of a DIV is hidden or if it is exposed.
This is the pseudocode:
if(DIV != VISIBLE) // not visible { show content }
Any JQuery Experts able to assist me?
Thanks, Robert
If you're trying to just show a div which is hidden, then you don't actually need to do any checks at all:
$('#myDiv').show();
Regardless of its state beforehand, it'll end up visible now.
However, if you want to perform other actions depending on whether the content is visible or not, then you'll need to check:
if ($('#myDiv').is(":hidden"))
// or
if ($('#myDiv:hidden').length)
// or
if ($('#myDiv:not(:visible)')) { // you get the idea...
//perform your actions
}
All other answers are fine, but this is just to translate your pseudocode into actual javascript code:
if (!$('div').is(':visible')) {
$('div').show();
}
The following will display a DIV named myDiv
if it is hidden. Note that if you want to do other stuff, you can also use each() rather than show and do other operations on $(this) inside each.
$('div#myDiv:hidden').show();
This will test to see if you selected any hidden elements with the id "mydiv":
if ( $("#mydiv:hidden").length > 0)
{
//
}
Edit: Simplified selector. Had to look it up :/
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