13

i am developin one application using jquery. i want to know the status of the div wheather the div is show state or hide state something like this:

if($("#test").show()==true) 
{
//some operration
}
else
{
//some operration
}

alert($("#test").show()==true); always shows false.

please help me...

Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
user601367
  • 2,308
  • 12
  • 34
  • 44

3 Answers3

33

You can use is() and the :visible selector.

if( $('#test').is(':visible') ) { ... }
Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
AndrewR
  • 6,668
  • 1
  • 24
  • 38
5

try

$(element).is(":visible") 

Reference
Note : hidden fails on elements that have width but no height.

Community
  • 1
  • 1
xkeshav
  • 53,360
  • 44
  • 177
  • 245
1

is(':visible') is, of course, correct.

In pretty much all my jQuery applications, I introduce a simple plugin isVisible.

$.fn.isVisible = function() {
    return $.expr.filters.visible(this[0]);
};

This is about 50 times faster than the above function (jsPerf example) for exactly the same functionality.

if ($('#yourElement').isVisible()) {
lonesomeday
  • 233,373
  • 50
  • 316
  • 318