How do you get the rendered height of an element?

前端 未结 18 2320
情书的邮戳
情书的邮戳 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:25

    Try one of:

    var h = document.getElementById('someDiv').clientHeight;
    var h = document.getElementById('someDiv').offsetHeight;
    var h = document.getElementById('someDiv').scrollHeight;
    

    clientHeight includes the height and vertical padding.

    offsetHeight includes the height, vertical padding, and vertical borders.

    scrollHeight includes the height of the contained document (would be greater than just height in case of scrolling), vertical padding, and vertical borders.

提交回复
热议问题