Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the status of the div in jquery?

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

like image 596
user601367 Avatar asked Apr 15 '11 06:04

user601367


People also ask

How check div is visible or not in jQuery?

Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.

How do you make a div visible in jQuery?

Projects In JavaScript & JQuery To toggle a div visibility in jQuery, use the toggle() method. It checks the div element for visibility i.e. the show() method if div is hidden. And hide() id the div element is visible. This eventually creates a toggle effect.

Is visible in jQuery?

The :visible selector in jQuery is used to select every element which is currently visible. It works upon the visible elements. The elements that are consuming space in the document are considered visible elements. The height and width of visible elements are larger than 0.


2 Answers

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

if( $('#test').is(':visible') ) { ... }
like image 155
AndrewR Avatar answered Oct 02 '22 16:10

AndrewR


try

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

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

like image 43
diEcho Avatar answered Oct 02 '22 15:10

diEcho