Wednesday, December 15, 2010

jQuery check element is visible : How to check if div is visible with jQuery

Unlike Prototypejs where there is a dedicate function .visible() that return true/false when element style is 'none', jQuery has this function .is() to check the value of given properties.


This is how you can determine if an element is visible.



<div id="target" style="display:none"></div>



if( $('#target').is(':visible') ) {
// this element is visible
}
// Check if its hidden
if( $('#target').is(':hidden') ) {
// this element is hidden
}