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()
.
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()
.
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