How to find out if an element is hidden with JavaScript?

To find out if an element is hidden with JavaScript, the code is as follows −


 Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .hiddenDiv {
      width: 100%;
      padding: 20px;
      text-align: center;
      background-color: lightblue;
      margin-top: 20px;
      display: none;
      font-size: 20px;
   .showBtn {
      border: none;
      padding: 15px;
      font-size: 18px;
      background-color: rgb(86, 25, 155);
      color: white;
<h1>Find hidden element using JavaScript</h1>
<h2>Click on the below button to display hidden element</h2>
<button class="showBtn">Show element</button>
<div class="hiddenDiv">
This is a DIV element
   document.querySelector(".showBtn").addEventListener("click", showHidden);
   function showHidden() {
      var x = document.querySelector(".hiddenDiv");
      if (window.getComputedStyle(x).display === "none") { = "block";


The above code will produce the following output −

On clicking the “Show element” button −