Get Div clientWidth and offsetWidth

You can get the Div width dynamically using JavaScript DOM methods. JavaScript document object provides getElementById function that returns the HTML object according to the specified id of the element. The object returned by getElementById method allows you to access the width of the specified Div element. Following are the properties accessible through JavaScript DOM:

1. clientWidth

2. offsetWidth

You can learn more about these properties from the tutorial link provided at the bottom and top of this sample.

Try the sample below to learn the working of JavaScript code for retrieving the width of the HTML div element dynamically:

Edit this code and click update to view output