Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get content width of an element

Tags:

javascript

offsetWidth isn't good enough for me right now, as this includes padding and border width. I want to find out the content width of the element. Is there a property for that, or do I have to take the offsetWidth and then subtract the padding and border width from the computed style?

like image 693
Niet the Dark Absol Avatar asked Jul 03 '13 00:07

Niet the Dark Absol


1 Answers

I would suggest either scrollWidth or the clientWidth depending on whether you want to account for the scrollbar.

Check out Determining the dimensions of elements or the specification itself.

like image 147
martineno Avatar answered Oct 30 '22 07:10

martineno