As in the subject, how can one get the total width of an element, including its border and padding, using jQuery? I’ve got the jQuery dimensions plugin, and running .width() on my 760px-wide, 10px padding DIV returns 760.
Perhaps I’m doing something wrong, but if my element manifests itself as 780 pixels wide and Firebug tells me that there’s 10px padding on it, but calling .width() only gives 760, I’d be hard pressed to see how.
Thanks for any suggestions.
[Update]
The original answer was written prior to jQuery 1.3, and the functions that existed at the time where not adequate by themselves to calculate the whole width.
Now, as J-P correctly states, jQuery has the functions outerWidth and outerHeight which include the
borderandpaddingby default, and also themarginif the first argument of the function istrue[Original answer]
The
widthmethod no longer requires thedimensionsplugin, because it has been added to thejQuery CoreWhat you need to do is get the padding, margin and border width-values of that particular div and add them to the result of the
widthmethodSomething like this:
Split into multiple lines to make it more readable
That way you will always get the correct computed value, even if you change the padding or margin values from the css