Get height of dynamically resized div height

How can I determine (using jQuery?) The height of the div? Its height is not defined in CSS, so it is fluid and based on content.

I tried $ ('# div'). height () - which returns 0.

Ideas?

EDIT: (code)

$(document).ready(function () {
    PositionBottomPicture();
});

function PositionBottomPicture() {
    var parentOffset = $('#left_pane').offset();
    var parentsHeight = $('#left_pane').height();
    var childsTopPostion = (parentOffset.top + parentsHeight);


    $('#bottom_pic').offset({ top: childsTopPostion, left: parentOffset.left });
}

CSS:

#left_pane 
{
    float: left;
    margin-left: 27px;
    position: relative;
}

where 'left_pane' and 'bottom_pic' are div.

Thank!

+3
source share
3 answers

the problem is that you probably can't wait for the div to fit in the DOM;

try something line by line:

$(document).ready(function(){
        var h = $("#div").height();
        var w = $("#div").width();
;})

using the Document Ready tool provided by jQuery, it will wait for the item to be processed.

+4
source

Check out this jsfiddle example, it will reconfigure width and height

http://jsfiddle.net/b2DNP/

0

"left_pane" , .

0

Source: https://habr.com/ru/post/1778841/


All Articles