How do you get the rendered height of an element?

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

    I think the best way to do this in 2020 is to use plain js and getBoundingClientRect().height;

    Here's an example

    let div = document.querySelector('div');
    let divHeight = div.getBoundingClientRect().height;
    
    console.log(`Div Height: ${divHeight}`);
    How high am I?

提交回复
热议问题