How do I get the height and width of a div.
My divs's height and width is set to auto so it scales up or down depending on the size of its content at diffrent device screen sizes. How do I get the div's height at any point in time on any device.
Admin
2022-03-31
In your page's javascript section or file paste in the code below
var x = document.getElementById('div-id').clientHeight
var y = document.getElementById("div-id").clientWidth
console.log('div height', x)
console.log('div width', y)
Whereby "div-id" is the id of the div whose height you wish to know. You can replace it with your own custom id.
The "clientHeight" gets the specific height of the div with id of "div-id".
The "clientWidth" gets the specific width of the div with id of "div-id".
Add Message
Click on the button below to add a new message to this thread
Tags
Thread detail
Satus: Open
Messages: 1Started: 2022-03-31Thread Create
Click the button below to start a new thread for your question
loading..
Privacy Policy
By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.