Bax
Bax

Reputation: 4476

Jquery 1.8, checking if the item is hidden

I have a div element <div id='someId' style="visibility: hidden;"></div>

$(#someId).css('visibility'); // returns "hidden" $(#someId).is(':hidden'); // returns false $(#someId).is(':visible'); // returns true

Is this a bug in JQuery 1.8 or I didn't figure out something ?

Upvotes: 2

Views: 208

Answers (4)

zessx
zessx

Reputation: 68790

:hidden selector can refers to :

  • display: none
  • type="hidden"
  • width: 0px; height: 0px
  • An ancestor element is hidden.

So visibility: hidden doesn't enter in those cases.

See jQuery doc here : http://api.jquery.com/hidden-selector/

EDIT

To check visibility property :

if($("#someId").css('visibility') == 'hidden') {
   /* some code */
}

Upvotes: 3

Nishu Tayal
Nishu Tayal

Reputation: 20840

Please refer the following jquery links :

:hidden Selector

:visible Selector

Here reason is clearly mentioned that Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout

Upvotes: 2

Jan Wiemers
Jan Wiemers

Reputation: 341

is(':visible') and is('hidden') takes the display Property as reference

Upvotes: 0

Danil Speransky
Danil Speransky

Reputation: 30453

From jquery.com:

Elements can be considered hidden for several reasons:

They have a CSS display value of none.
They are form elements with type="hidden".
Their width and height are explicitly set to 0.
An ancestor element is hidden, so the element is not shown on the page.

Upvotes: 1

Related Questions