Ben
Ben

Reputation: 1022

jquery - is it possible to see if a cached element is hidden or not

I've cached a DOM element in jquery and wondered how i can see if it's hidden or not.

I have no problem doing by a normal selector. With a normal selector i'd do something like this if statement:

if('.someClass:hidden') {
    console.log('hidden')
} 
else {
    console.log('not hidden');
} 

But instead of .someClass i had the element cached. Like this, details being the cached element:

$this = $(this);
details = $this.find(".details");

Many Thanks

B

Upvotes: 1

Views: 43

Answers (1)

wirey00
wirey00

Reputation: 33661

for a cached element you can use is()

var $cachedElement = $('#cachedElement');
if($cachedElement.is(':hidden')){
   console.log('hidden')
}else {
   console.log('not hidden');
} 

Upvotes: 5

Related Questions