คุณสามารถใช้ 2 คุณสมบัติคือ clientHeight และ offsetHeight เพื่อดูความสูงของ div
clientHeightรวม padding ของ divoffsetHeightรวม padding, scrollbar, และ border ของ div
ตัวอย่าง
ตัวอย่างเช่น หากคุณมี HTML ดังนี้
<div id="myDiv" height="400px"></div>
คุณสามารถดูความสูงได้ด้วย
const height = document.querySelector('#myDiv').offsetHeight console.log(height)ผลลัพธ์
จะได้ผลลัพธ์ดังนี้
400