使用jQuery检查元素是否为"display:none"或单击时是否阻止 [英] Check, using jQuery, if an element is 'display:none' or block on click
问题描述
我想检查和排序隐藏的元素.是否可以找到所有属性display
和值none
的元素?
您可以使用:visible 显示可见元素,并:hidden 查找隐藏元素.此隐藏元素的display
属性设置为none
.
hiddenElements = $(':hidden');
visibleElements = $(':visible');
要检查特定元素.
if($('#yourID:visible').length == 0)
{
}
如果元素占用了文档中的空间,则认为它们是可见的. 可见元素的宽度或高度大于零, 参考
您还可以将 is()与:visible
if(!$('#yourID').is(':visible'))
{
}
如果要检查显示值,则可以使用 css()
if($('#yourID').css('display') == 'none')
{
}
如果使用显示,则display
可以具有以下值.
显示:无
显示:内联
显示:阻止
显示:列表项
显示:内嵌广告
在此处中检查所有可能的display
值的完整列表. /p>
要使用JavaScript检查显示属性
var isVisible = document.getElementById("yourID").style.display == "block";
var isHidden = document.getElementById("yourID").style.display == "none";
I want to check and sort elements that are hidden. Is it possible to find all elements with attribute display
and value none
?
You can use :visible for visible elements and :hidden to find out hidden elements. This hidden elements have display
attribute set to none
.
hiddenElements = $(':hidden');
visibleElements = $(':visible');
To check particular element.
if($('#yourID:visible').length == 0)
{
}
Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero, Reference
You can also use is() with :visible
if(!$('#yourID').is(':visible'))
{
}
If you want to check value of display then you can use css()
if($('#yourID').css('display') == 'none')
{
}
If you are using display the following values display
can have.
display: none
display: inline
display: block
display: list-item
display: inline-block
Check complete list of possible display
values here.
To check the display property with JavaScript
var isVisible = document.getElementById("yourID").style.display == "block";
var isHidden = document.getElementById("yourID").style.display == "none";
这篇关于使用jQuery检查元素是否为"display:none"或单击时是否阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!