Return the outer height of a <div> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*ww w .jav a2s . c om*/ <script> $(document).ready(function(){ $("button").click(function(){ document.getElementById("demo").innerHTML = "Outer height of div: " + $("div").outerHeight(); }); }); </script> </head> <body> <p id="demo"></p> <div style="height:100px;width:300px;padding:10px;margin:3px;background-color:lightblue;"> </div><br> <button>Display the outer height of div</button> </body> </html>
The outerHeight()
method returns the outer height of the first matched element.
The returned value from this method includes padding and border.
To include the margin, use outerHeight(true).
$(selector).outerHeight(include_Margin)
Parameter | Optional | Description |
---|---|---|
include_Margin | Optional. | whether or not to include the margin false - Default. Does not include the margin true - Includes the margin |