Using Javascript or HTML, how to get the height and width of a div or other element?

后端 未结 4 985
失恋的感觉
失恋的感觉 2021-01-25 21:32

I\'ve been trying for a while now to \'get\' the height and width of a div on my webpage. I\'ve tried many things, some are:

document.getElementById(\"header\").         


        
4条回答
  •  逝去的感伤
    2021-01-25 22:21

    if you don't use jQuery try this:

    document.getElementById('someDiv').clientHeight;
    document.getElementById('someDiv').offsetHeight;
    document.getElementById('someDiv').scrollHeight;
    

    Depend what you need.

提交回复
热议问题