ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://attacomsian.com/blog/javascript-check-element-hidden-visible |
| Last Crawled | 2026-04-02 16:53:17 (5 days ago) |
| First Indexed | 2022-07-30 20:33:13 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to check if an element is hidden or visible using JavaScript |
| Meta Description | A quick guide to learning how to check if an element is hidden or visible in DOM using JavaScript. |
| Meta Canonical | null |
| Boilerpipe Text | In JavaScript, the quickest way to check if an element is hidden or visible in DOM is to use the
getComputedStyle()
method. This method returns the
actual values of CSS properties
used to render an HTML element in DOM.
Let us say that we have got the following hidden HTML element:
.hidden
{
display
:
none
;
}
<
button
class
=
"
hidden
"
>
Click Me!
</
button
>
An HTML element can be hidden due to either
display:none
or
visibility:hidden
CSS properties.
Let us write a function that checks both these properties and returns a boolean value depicting the visibility status of the element:
const
isHidden
=
elem
=>
{
const
styles
=
window
.
getComputedStyle
(
elem
)
return
styles
.
display
===
'none'
||
styles
.
visibility
===
'hidden'
}
const
elem
=
document
.
querySelector
(
'button'
)
if
(
isHidden
(
elem
)
)
{
console
.
log
(
`
Element is hidden!!
`
)
}
else
{
console
.
log
(
`
Element is visible!!
`
)
}
// Element is hidden!!
If you are using jQuery, you can use the
:hidden
and
:visible
selectors to check if a
DOM element
is hidden or visible:
// Check if element is hidden
if
(
$
(
'button'
)
.
is
(
':hidden'
)
)
{
console
.
log
(
`
Element is hidden!!
`
)
}
// Check if element is visible
if
(
$
(
'button'
)
.
is
(
':visible'
)
)
{
console
.
log
(
`
Element is visible!!
`
)
}
✌️ Like this article?
Follow me on
Twitter
and
LinkedIn
.
You can also subscribe to
RSS Feed
. |
| Markdown | - [Blog](https://attacomsian.com/blog)
- [Topics](https://attacomsian.com/topics)
- [Newsletter](https://attacomsian.com/newsletter)
- [Work with us 🦄](https://fore.studio/?ref=attacomsian.com)
- [Advertise ✨](https://attacomsian.com/sponsors)
- [Search](https://attacomsian.com/blog/javascript-check-element-hidden-visible)
- [RSS Feed](https://feeds.feedburner.com/attacomsian)
Loading...
1. [Blog](https://attacomsian.com/blog)
2. �
# How to check if an element is hidden or visible using JavaScript
July 30, 2022
In JavaScript, the quickest way to check if an element is hidden or visible in DOM is to use the `getComputedStyle()` method. This method returns the [actual values of CSS properties](https://attacomsian.com/blog/javascript-get-css-styles#getting-rendered-styles) used to render an HTML element in DOM.
Let us say that we have got the following hidden HTML element:
```
.hidden {
display: none;
}
```
```
<button class="hidden">Click Me!</button>
```
An HTML element can be hidden due to either `display:none` or `visibility:hidden` CSS properties.
Let us write a function that checks both these properties and returns a boolean value depicting the visibility status of the element:
```
const isHidden = elem => {
const styles = window.getComputedStyle(elem)
return styles.display === 'none' || styles.visibility === 'hidden'
}
const elem = document.querySelector('button')
if (isHidden(elem)) {
console.log(`Element is hidden!!`)
} else {
console.log(`Element is visible!!`)
}
// Element is hidden!!
```
If you are using jQuery, you can use the `:hidden` and `:visible` selectors to check if a [DOM element](https://attacomsian.com/blog/getting-dom-elements-javascript) is hidden or visible:
```
// Check if element is hidden
if ($('button').is(':hidden')) {
console.log(`Element is hidden!!`)
}
// Check if element is visible
if ($('button').is(':visible')) {
console.log(`Element is visible!!`)
}
```
**✌️ Like this article?** Follow me on [Twitter](https://twitter.com/attacomsian) and [LinkedIn](https://linkedin.com/in/attacomsian). You can also subscribe to [RSS Feed](https://feeds.feedburner.com/attacomsian).
[\#JavaScript](https://attacomsian.com/topics/javascript)
### You might also like...
1. [Get the length of a Map in JavaScript](https://attacomsian.com/blog/javascript-map-get-length)
2. [Delete an element from a Map in JavaScript](https://attacomsian.com/blog/javascript-map-delete-element)
3. [Get the first element of a Map in JavaScript](https://attacomsian.com/blog/javascript-map-get-first-element)
4. [Get an element from a Map using JavaScript](https://attacomsian.com/blog/javascript-map-get-element)
5. [Update an element in a Map using JavaScript](https://attacomsian.com/blog/javascript-map-update-element)
6. [Add an element to a Map in JavaScript](https://attacomsian.com/blog/javascript-map-add-element)
Share it �

The simplest cloud platform for developers & teams. Start with a \$200 free credit.
[Learn more �](https://attacomsian.com/go/digitalocean)
### Buy me a coffee ☕
If you enjoy reading my articles and want to help me out paying bills, please consider buying me a coffee (\$5) or two (\$10). I will be highly grateful to you ✌️
Enter the number of coffees below:
Buy
## ✨ Learn to build modern web applications using JavaScript and Spring Boot
I started this blog as a place to share everything I have learned in the last decade. I write about modern JavaScript, Node.js, Spring Boot, core Java, RESTful APIs, and all things web development.
The newsletter is sent every week and includes early access to clear, concise, and easy-to-follow tutorials, and other stuff I think you'd enjoy! No spam ever, unsubscribe at any time.
Subscribe
Maker. Developer. Writer.
© 2026 Made with ❤️ by Atta
Products
- [DomBuck](https://www.dombuck.com/?utm_source=atta-footer)
- [StartupBase](https://startupbase.io/?utm_source=atta-footer)
- [AcquireBase](https://acquirebase.com/?utm_source=atta-footer)
- [Protips](https://protips.io/?utm_source=atta-footer)
Links
- [Articles](https://attacomsian.com/blog)
- [Topics](https://attacomsian.com/topics)
- [Advertise](https://attacomsian.com/sponsors)
- [Contact](mailto:hi@attacomsian.com)
Follow Me
- [Twitter](https://twitter.com/attacomsian)
- [LinkedIn](https://www.linkedin.com/in/attacomsian)
- [GitHub](https://github.com/attacomsian)
- [RSS Feed](https://feeds.feedburner.com/attacomsian)
Others
- [Privacy Policy](https://attacomsian.com/privacy)
- [Cookies](https://attacomsian.com/cookies)
- [Disclaimer](https://attacomsian.com/disclaimer)
### ✨ Learn to build modern web applications using JavaScript and Spring Boot
- JavaScript, Node.js & Spring Boot
- In-depth tutorials
- Super-handy protips
- Cool stuff around the web
- 1-click unsubscribe
- No spam, free-forever\!
Subscribe |
| Readable Markdown | In JavaScript, the quickest way to check if an element is hidden or visible in DOM is to use the `getComputedStyle()` method. This method returns the [actual values of CSS properties](https://attacomsian.com/blog/javascript-get-css-styles#getting-rendered-styles) used to render an HTML element in DOM.
Let us say that we have got the following hidden HTML element:
```
.hidden {
display: none;
}
```
```
<button class="hidden">Click Me!</button>
```
An HTML element can be hidden due to either `display:none` or `visibility:hidden` CSS properties.
Let us write a function that checks both these properties and returns a boolean value depicting the visibility status of the element:
```
const isHidden = elem => {
const styles = window.getComputedStyle(elem)
return styles.display === 'none' || styles.visibility === 'hidden'
}
const elem = document.querySelector('button')
if (isHidden(elem)) {
console.log(`Element is hidden!!`)
} else {
console.log(`Element is visible!!`)
}
// Element is hidden!!
```
If you are using jQuery, you can use the `:hidden` and `:visible` selectors to check if a [DOM element](https://attacomsian.com/blog/getting-dom-elements-javascript) is hidden or visible:
```
// Check if element is hidden
if ($('button').is(':hidden')) {
console.log(`Element is hidden!!`)
}
// Check if element is visible
if ($('button').is(':visible')) {
console.log(`Element is visible!!`)
}
```
**✌️ Like this article?** Follow me on [Twitter](https://twitter.com/attacomsian) and [LinkedIn](https://linkedin.com/in/attacomsian). You can also subscribe to [RSS Feed](https://feeds.feedburner.com/attacomsian). |
| Shard | 70 (laksa) |
| Root Hash | 8353060396728727070 |
| Unparsed URL | com,attacomsian!/blog/javascript-check-element-hidden-visible s443 |