Friday, 22 July 2011

jQuery height() vs outerHeight()

.height()
Get the current computed height for the first element in the set of matched elements. This does not include the padding, border and margin.

.outerHeight([includeMargin])
Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin.

"includeMargin" is a optional boolean indicating whether to include the element's margin in the calculation.

$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document

$("#IdofYourDIV").height(); // returns height of "IdofYourDIV" excluding padding, border and margin

$("#IdofYourDIV").outerHeight(); // returns height of "IdofYourDIV" including padding and border but excluding margin

$("#IdofYourDIV").outerHeight(true); // returns height of "IdofYourDIV" including padding, border and margin

No comments:

Post a Comment