Retrieve the width of div element in JavaScript

In many situations in web design or development, you may need to get the width of div element for some reasons. Here in this post, I am just going to show you simple code snippet which can be used to get the width of an HTML div element.


The above JavaScript code will return you the width of the div element. It includes borders width also.

If you don’t want to include border width then go with the below code:


The above code will not include the border and take the width of a div element by excluding the border width.

Get the width of HTML div element using jQuery

If you want to retrieve the width of an HTML element using jQuery JavaScript framework then below is the given jQuery code which will do that:


Below is given some more methods:

  • innerWidth() – Returns the width of an element (includes padding).
  • outerWidth() – Returns the width of an element (includes padding and border).

Leave a Reply

Your email address will not be published. Required fields are marked *