Get the height of the hidden element in jQuery
An HTML element can be hidden with the help of .hide() jQuery function or we can hide easily by making visibility equals hidden in CSS. We can easily find the height of this hidden element in jQuery.
There are two kinds of height that are defined with the every HTML element i.e, innerHeight and the outerHeight of the element:
- innerHeight: This height is considered when the width of the border is not considered for the selected element.
- outerHeight: This height is considered when the width of the border is considered for the selected element.
Example-1: This example show how to calculate innerHeight of the hidden element.
<!DOCTYPE html> <html> <head> <script src= </script> <script> $(document).ready(function() { $("#btn1").click(function() { var demo = $("div").innerHeight(); $("#demo").text(demo); }); }); </script> <style> div { width: 310px; height: 80px; font-weight: bold; color: green; font-size: 25px; border: 1px solid green; visibility: hidden; } body { border: 1px solid green; padding: 10px; width: 300px; } </style> </head> <body> <div> </div> <p id="demo"> Here the height of the hidden "div" element will appear. </p> <button id="btn1">Submit</button> </body> </html> |
Output:
Before Click:

After Click:
Here, border width will not be added to the result.

Example-2: This example show how to calculate outerHeight of the hidden element.
<!DOCTYPE html> <html> <head> <script src= </script> <script> $(document).ready(function() { $("#btn1").click(function() { var demo = $("div").outerHeight(); $("#demo").text(demo); }); }); </script> <style> div { width: 310px; height: 80px; font-weight: bold; color: green; font-size: 25px; border: 1px solid green; visibility: hidden; } body { border: 1px solid green; padding: 10px; width: 300px; } </style> </head> <body> <div> </div> <p id="demo"> Here the height of the hidden "div" element will appear. </p> <button id="btn1">Submit</button> </body> </html> |
Output:
Before Click:

After Click:
Here, border width will be added to the result.

Recommended Posts:
- How to check if an element is hidden in jQuery?
- How to create hidden form element on the fly using jQuery ?
- jQuery | :hidden Selector
- How to detect value change on hidden input field in JQuery ?
- How to display hidden element when a user starts typing using JavaScript ?
- Difference between 'hidden' and 'aria-hidden' attributes in HTML
- jQuery | height() and innerHeight() with Examples
- How to animate div width and height on mouse hover using jQuery ?
- How to remove parent element except its child element using jQuery ?
- jQuery | Move an element into another element
- How to change the element id using jQuery ?
- How to select an element by name with jQuery?
- How to create a div element in jQuery ?
- How to get a DOM Element from a jQuery Selector ?
- jQuery | element Selector
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.
Improved By : shubham_singh


