jQuery: how to check if an element is hidden?

2

How to check if an element is visible or hidden in jQuery?

For example, an element can be hidden using .hide() , visible using .show() or switch between hidden / visible with .toggle() .

    
asked by anonymous 03.05.2015 / 17:51

1 answer

3

Use the :visible: and :hidden selectors. [1]

var isVisible = $( "#myDiv" ).is( ":visible" );
var isHidden = $( "#myDiv" ).is( ":hidden" );

In addition, you can use them directly in the selector:

$( "#myDiv:visible" ).animate({
    left: "+=200px"
}, "slow" );

> link

Response inspired by Stack Overflow response.

    
03.05.2015 / 17:51