Jquery 1.8,检查项目是否隐藏

时间:2012-08-21 10:06:08

标签: javascript jquery html css

我有一个div元素<div id='someId' style="visibility: hidden;"></div>

$(#someId)的CSS( '能见度'); //返回“隐藏” $(#someId)。是( ':隐藏'); //返回false $(#someId)。是( ':可见'); //返回true

这是JQuery 1.8中的错误还是我没弄明白?

4 个答案:

答案 0 :(得分:3)

:hidden选择器可以引用:

  • display: none
  • type="hidden"
  • width: 0px; height: 0px
  • 隐藏祖先元素。

所以visibility: hidden在这些情况下不会进入。

请参阅此处的jQuery文档:http://api.jquery.com/hidden-selector/

修改

检查visibility属性:

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

答案 1 :(得分:2)

请参阅以下jquery链接:

:hidden Selector

:visible Selector

这里明确提到具有可见性:隐藏或不透明度:0的元素被认为是可见的,因为它们仍占用布局中的空间

答案 2 :(得分:1)

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

答案 3 :(得分:0)

是(':visible')并且是('hidden')将显示属性作为参考