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...
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.
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.
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.
You can use is() and the :visible selector.
if( $('#test').is(':visible') ) { ... }
try
$(element).is(":visible")
Reference
Note : hidden fails on elements that have width but no height.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With