Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select by CSS styles in jQuery?

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]");
like image 497
Foobarbis Avatar asked Sep 03 '10 22:09

Foobarbis


Video Answer


1 Answers

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';
               });

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

like image 138
Nick Craver Avatar answered Sep 29 '22 06:09

Nick Craver