HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Learn how to find out if an element is hidden with JavaScript
If the <div> element is hidden, do something:
function myFunction() {
var x = document.getElementById("myDIV");
if (window.getComputedStyle(x).display === "none") {
// Do something..
}
}
Try it Yourself »
display:none
(like in the example above), the element will not take up any space.
To find out if an element is hidden with visibility:hidden
, see the example below. This "hidden" element will take up space.
function myFunction() {
var x = document.getElementById("myDIV");
if (window.getComputedStyle(x).visibility === "hidden") {
// Do something..
}
}
Try it Yourself »
Tip: Also check out How To - Toggle Hide/Show.
Tip: For more information about Display and Visibility, read our CSS Display Tutorial.