如何通过CSS样式在jQuery中进行选择? [英] How to select by CSS styles in jQuery?

查看:116
本文介绍了如何通过CSS样式在jQuery中进行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到所有具有CSS样式 display:none 的父元素。我似乎不能得到它的工作,但。这是我得到的:

I'm trying to find all the parent elements that have the CSS style display:none. I can't seem to get it to work though. Here's what I've got:

var $parents = $(...).parents("[css=display:none]");


推荐答案

如果你想要 c:display; none; display:none; c>),您可以使用 .filter() .css() 得到这些父母,像这样:

If you want the ones that are actually display: none; (not just possibly contained in another display: none;), you can use .filter() and .css() to get those parents, like this:

var $parents = $(...).parents().filter(function() {
                  return $(this).css('display') == 'none';
               });

这将获得父项,然后过滤它们以获得 display:none; 特定父项

This gets the parents, then filters them to get only the ones that are display: none; on that specific parent.

这篇关于如何通过CSS样式在jQuery中进行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆