jQuery | :hidden Selector

The hidden selector selects hidden elements to work upon.
Syntax:

$(":hidden")
    Hidden elements are elements that are:

  • Set to display:none
  • Form elements with type=”hidden”
  • Width and height set to 0
  • A hidden parent element (this also hides child elements)

Example-1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <!-- Jquery CDN -->
    <script src=
  </script>
    <!-- Jquery demonstration script -->
    <script>
        $(document).ready(function() {
            $("h1:hidden").show(5000);
        });
    </script>
    <!-- Script ends here -->
</head>
  
<body>
    <center>
        <h1 style="display:none;">
          GeeksforGeeks
      </h1>
        <p>
          Hidden attribute example
      </p>
        <p>
          The above line will show up gradually.
      </p>
  
    </center>
</body>
  
</html>

chevron_right


Output:
Before Animation:

After Animation:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!doctype html>
<html lang="en">
  
<head>
    <title>
      Complex Animation Using Hidden Attribute
  </title>
    <style>
        h1 {
            color: green;
        }
          
        div {
            width: 70px;
            height: 40px;
            background: green;
            margin: 5px;
            float: left;
        }
          
        span {
            display: block;
            clear: left;
            color: black;
        }
          
        .starthidden {
            display: none;
        }
    </style>
    <script src=
  </script>
</head>
  
<body>
    <center>
        <h1>GeeksforGeeks</h1>
    </center>
    <span></span>
    <div></div>
    <div style="display:none;">
      Hidden element
  </div>
    <div class="starthidden">
      Hidden element2
  </div>
  
    <div></div>
    <div style="display:none;">
      Hidden element
  </div>
    <div class="starthidden">
      Hidden element2
  </div>
  
    <div></div>
  
    <form>
        <input type="hidden">
        <input type="hidden">
        <input type="hidden">
    </form>
  
    <span></span>
  
    <script>
        var hiddenElements = $("body").find(":hidden").not("script");
  
        $("span:first").text("We have found " +
                             hiddenElements.length + 
                             " hidden elements total.");
        $("div:hidden").show(1000);
        $("span:last").text("We have found " +
                            $("input:hidden").length 
                            + " hidden inputs.");
    </script>
  
</body>
  
</html>

chevron_right


Output:
Before Animation:

After Animation:

Note: This selector will not work on elements with visibility: hidden.

References: https://api.jquery.com/hidden-selector/



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.