jQuery .outerHeight() gets the current height for the first element selected
Syntax and Description
.outerHeight([includeMargin])
gets the current height for the first element
in the matched elements, including padding and border.
includeMargin
is a Boolean indicating whether to include the
element's margin in the calculation.
The return value is the height of the element, along with its top and bottom padding, border, and optionally margin, in pixels.
If includeMargin
is omitted or false,
the padding and border are included in the
calculation; if it's true, the margin is also included.
This method is not applicable to window and document objects, for these use .height() instead.
Outer height of a div element
The following code set the width for a div element first and then it gets the outer height.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from ww w .j av a 2s .c o m-->
$("div").width(300);
alert($("div").outerHeight());
});
</script>
<style>
div{
width:200px;
height:100px;
overflow:auto;
}
h1 { width:1000px;height:1000px; }
</style>
</head>
<body>
<body>
<div><h1>java2s.com</h1></div>
</body>
</html>