How do you get the rendered height of an element?

前端 未结 18 2593
情书的邮戳
情书的邮戳 2020-11-22 03:11

How do you get the rendered height of an element?

Let\'s say you have a

element with some content inside. This content inside is going to st
18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 03:31

    You can use .outerHeight() for this purpose.

    It will give you full rendered height of the element. Also, you don't need to set any css-height of the element. For precaution you can keep its height auto so it can be rendered as per content's height.

    //if you need height of div excluding margin/padding/border
    $('#someDiv').height();
    
    //if you need height of div with padding but without border + margin
    $('#someDiv').innerHeight();
    
    // if you need height of div including padding and border
    $('#someDiv').outerHeight();
    
    //and at last for including border + margin + padding, can use
    $('#someDiv').outerHeight(true);
    

    For a clear view of these function you can go for jQuery's site or a detailed post here.

    it will clear the difference between .height() / innerHeight() / outerHeight()

提交回复
热议问题