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.

message profile
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-31
loading..

DEVMAESTERS

Newsletter

Services

Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment

Contact

Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
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.