开发者

how to get DIV object reality height in javascript?

开发者 https://www.devze.com 2023-01-29 11:14 出处:网络
please see: demo $(\"#stdout\").height() 开发者_JAVA百科return 18px I want to get thereality height ( height + padding + border ) 200px

please see: demo

$("#stdout").height()

开发者_JAVA百科return 18px

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

how to do?

thank for help :)


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 )


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消