Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get DIV object reality height in javascript?

please see: demo

$("#stdout").height()

return 18px

I want to get the reality height ( height + padding + border ) 200px

how to do?

thank for help :)

like image 315
Koerr Avatar asked Mar 25 '26 07:03

Koerr


2 Answers

See .outerHeight()

$("#stdout").outerHeight();
// returns ( height + padding + border )

And if you want to include margin as well:

$("#stdout").outerHeight( true );
// returns ( height + padding + border + margin )
like image 101
BGerrissen Avatar answered Mar 27 '26 20:03

BGerrissen


Here's another way:

$.fn.getHeight = function()
{
    return ($(this).height() + parseInt($(this).css("padding-top")) + parseInt($(this).css("padding-bottom")) + parseInt($(this).css("borderTopWidth")) + parseInt($(this).css("borderBottomWidth")));
};

$.fn.getWidth = function()
{
    return ($(this).width() + parseInt($(this).css("padding-left")) + parseInt($(this).css("padding-right")) + parseInt($(this).css("borderLeftWidth")) + parseInt($(this).css("borderRightWidth")));
};

To use this function, simply call:

obj.getHeight()

Or:

$(this).getHeight();
like image 22
Chris Ingis Avatar answered Mar 27 '26 20:03

Chris Ingis