jQuery/CSS - 如何选择文档中的所有 li display none?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7384320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:46:06  来源:igfitidea点击:

jQuery/CSS - How do I select all the li display none in the document?

jquerycssjquery-selectors

提问by Matt

jQuery/CSS - How do I select all the <li style="display: none;">in the document?

jQuery/CSS - 如何选择<li style="display: none;">文档中的所有内容?

回答by Jose Faeti

While the chosen answer works in your case, it's still doesn't answer the question. Same for the answers posted by other people, so I decided to write this anyway.

虽然选择的答案适用于您的情况,但它仍然没有回答问题。其他人发布的答案也是如此,所以我还是决定写这个。

$('li[style*="display: none"]')

This will return a jQuery object representing a list of all the <li>elements in your document with a style property containing "display: none".

这将返回一个 jQuery 对象,该对象表示<li>文档中所有元素的列表,其样式属性包含“display: none”。

This is a different thing that finding all the hidden elements in the document.

这与查找文档中的所有隐藏元素不同。

回答by Guffa

There is a selector to find hidden elements:

有一个选择器来查找隐藏元素:

$('li:hidden')

Note that this finds all lielements that are not visible, not only because they have the style display:noneapplied to them. The element could be hidden for example by setting their height to zero, or hiding the parent element.

请注意,这会找到所有li不可见的元素,不仅因为它们display:none应用了样式。例如,可以通过将元素的高度设置为零或隐藏父元素来隐藏元素。

回答by Allen Liu

Try this

尝试这个

$("li").filter(function() { return $(this).css("display") == "none" })

回答by Pranay Rana

$('li:hidden')- Try as per jquery document it will work

$('li:hidden')- 按照 jquery 文档尝试它会起作用

Fore more dtail - :hidden Selector

更多细节 - :hidden Selector

回答by balexandre

I would say:

我会说:

$("li").not(":visible")

or

或者

$("li:hidden")

then do everything inline or use .each()to loop through all.

然后内联执行所有操作或用于.each()循环遍历所有内容。

回答by Liviu Dragulin

Since jQuery 1.3.2, an element is visible if its browser-reported offsetWidth or offsetHeight is greater than 0. What does this change mean? It means that if your element's CSS display is “none”, or any of its parent/ancestor element's display is “none”, or if the element's width is 0 and the element's height is 0 then an element will be reported as hidden. See here: http://blog.jquery.com/2009/02/20/jquery-1-3-2-released/

从 jQuery 1.3.2 开始,如果浏览器报告的 offsetWidth 或 offsetHeight 大于 0,则元素是可见的。这个变化意味着什么?这意味着如果您元素的 CSS 显示为“none”,或者其任何父/祖先元素的显示为“none”,或者如果元素的宽度为 0 且元素的高度为 0,则元素将被报告为隐藏。见这里:http: //blog.jquery.com/2009/02/20/jquery-1-3-2-released/

Example:

例子:

This means the lielement is recognized as hidden only if you have a parent that has display: nonestyle:

这意味着仅当您的父元素具有display: none样式时,li元素才会被识别为隐藏:

$("li:hidden")