I want to check and sort elements that are hidden. Is it possible to find all elements with attribute display
and value none
?

- 30,738
- 21
- 105
- 131

- 3,623
- 2
- 19
- 22
-
If you should use `.find()` then: `if($(this).find('.wrap').is(':visible')) { … }` – Avatar Jun 14 '23 at 09:08
8 Answers
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";

- 146,340
- 25
- 209
- 204
-
well, in my scenario, each element has an ID, so the trick works for me :) – Nicholas Francis Apr 10 '13 at 12:00
-
2@NicholasFrancis, I have updated my answer to find out all elements which are hidden. – Adil Apr 10 '13 at 12:05
-
Does it check inline css also. I have css `display: block;` written inline coming from jquery. i am unable to check it with your method. help me. – Gaurav Manral Aug 22 '14 at 06:23
-
Is jQuery added and you are accessing the element after being added to DOM? Can you show me the code? It would be better to make a demo on http://jsfiddle.net/ – Adil Aug 22 '14 at 07:08
-
-
var isVisible = document.getElementById("yourID").style.display == "block"; var isHidden = document.getElementById("yourID").style.display == "none"; – Adil Jan 17 '17 at 08:17
-
-
We can't expect better answer from this one. Very well explained. – Nana Partykar Feb 02 '18 at 11:13
-
if( $('.serach_outer:visible').length == 0 ) worked for me with a class name, which I think it's impossible in vanilla JS, at least haven't worked for me in the past. – Jean G.T Aug 13 '21 at 07:35
$("element").filter(function() { return $(this).css("display") == "none" });

- 2,738
- 3
- 34
- 61
-
13+1: This is actually more useful than the accepted answer *for the question asked*, as this will work even if a parent element has `style="display: none;"`. Answers using `:visible` and `:hidden` will fail if you want specific element visibility and a parent element is hidden as those selectors return overall visibility on the page (which was not the question asked). – iCollect.it Ltd May 02 '14 at 09:41
-
-
For a tabbing plugin, it was setting `visibility: 'hidden';` in css, so the check ended up also checking: `$(this).css('visibility') != 'hidden'` – phyatt Mar 05 '18 at 21:20
-
In my case this is more useful, since I have 2 error messages and one of those have `display = none` and the other `display = block`, but the page have other tabs, that causes these both messages be not visible, when I am in the other tabs,... but 1 message is visible and this selector will help me with that. – Jaider Dec 17 '20 at 02:33
Yes, you can use the cssfunction. The below will search all divs, but you can modify it for whatever elements you need
$('div').each(function(){
if ( $(this).css('display') == 'none')
{
//do something
}
});

- 1,219
- 1
- 15
- 17
There are two methods in jQuery to check for visibility:
$("#selector").is(":visible")
and
$("#selector").is(":hidden")
You can also execute commands based on visibility in the selector;
$("#selector:visible").hide()
or
$("#selector:hidden").show()

- 6,629
- 1
- 35
- 65
-
7Note: this will *not* return the specific visible attribute of the selected elements, as the question asks, as `:visible` also depends on parent ancestor visibility. If an ancestor is `display: none` all descendants will not be visible regardless of `display` state. – iCollect.it Ltd May 02 '14 at 09:45
Use this condition:
if (jQuery(".profile-page-cont").css('display') == 'block'){
// Condition
}

- 30,738
- 21
- 105
- 131

- 324
- 2
- 8
$('#selector').is(':visible');

- 6,690
- 3
- 36
- 64
-
3Note: this will *not* return the specific visible attribute of the selected elements, as the question asks, as `:visible` also depends on parent ancestor visibility. If an ancestor is `display: none` all descendants will not be visible regardless of `display` state. – iCollect.it Ltd May 02 '14 at 09:45
Just another shortcut i personally prefer more than .is() or .length:
if($('.myclass:visible')[0]){
// is visible
}
which will just return undefined
if no dom-element found for selector .myclass:visible

- 17,409
- 11
- 76
- 117