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
  • 23,624
  • 4
  • 75
  • 75
user601367
  • 2,178
  • 12
  • 33
  • 44

3 Answers3

32

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

if( $('#test').is(':visible') ) { ... }
Amol M Kulkarni
  • 19,000
  • 32
  • 110
  • 158
AndrewR
  • 6,360
  • 1
  • 20
  • 37
5

try

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

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

Community
  • 1
  • 1
diEcho
  • 50,018
  • 37
  • 156
  • 230
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
  • 215,182
  • 48
  • 300
  • 305