Skip to content
Related Articles

Related Articles

jQuery | height() and innerHeight() with Examples
  • Last Updated : 13 Feb, 2019

The height() is an inbuilt method in jQuery which is used to check the height of an element but it will not check the padding, border and margin of the element.
Syntax:

$("param").height()

Parameters : This function do not accept any parameter.
Return value : It returns height of the selected element.

jQuery code to show the working of the height() function

Code #1:




<html>
  
<head>
                 jquery/3.3.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                var msg = "";
                msg += "height of div: " + $("#demo").height();
                $("#demo").html(msg);
            });
        });
    </script>
    <style>
        #demo {
            height: 150px;
            width: 350px;
            padding: 10px;
            margin: 3px;
            border: 1px solid blue;
            background-color: lightgreen;
        }
    </style>
</head>
  
<body>
    <div id="demo"></div>
    <button>Click Me!!!</button>
    <p>Click on the button and check the height of the
       element(excluding padding).</p>
</body>
  
</html>


Output:
Before clicking on “Click Me” button-

After clicking on “Click Me” button-

jQuery also include innerHeight() method i.e, it used to check inner height of the element including padding.
Syntax:

$("param").innerHeight()

Parameters: This function do not accept any parameter.
Return value: It returns the inner height of the selected element.
Code #2:




<html>
  
<head>
                 jquery/3.3.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                var msg = "";
                msg += "Inner Height of div: " + $("#demo").
                        innerHeight() + "</br>";
                $("#demo").html(msg);
            });
        });
    </script>
</head>
<style>
    #demo {
        height: 150px;
        width: 350px;
        padding: 10px;
        margin: 3px;
        border: 1px solid blue;
        background-color: lightgreen;
    }
</style>
  
<body>
    <div id="demo"></div>
    <button>Click Me!!!</button>
    <p>Click on the button and check the innerHeight of
       an element(includes padding).</p>
</body>
  
</html>


Output:
Before clicking on “Click Me” button-

After clicking on “Click Me” button-

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :