jQuery dimensions
With jQuery, it is easy to work with the dimensions of elements and the browser window.
jQuery dimension methods
jQuery provides several important methods for working with dimensions:
- width()
- height()
- innerWidth()
- innerHeight()
- outerWidth()
- outerHeight()
jQuery dimensions

jQuery width() and height() methods
The width() method sets or returns the width of an element (not including padding, border or margin).
The height() method sets or returns the height of an element (not including padding, border or margin).
The following example returns the width and height of the specified
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
var
txt
=
"
"
;
txt
+=
"
The width of the div is:
"
- $
(
"
#div1
"
)
.
width
(
)
"
"
;
txt
+=
"
The height of the div is:
"
- $
(
"
#div1
"
)
.
height
(
)
; $
(
"
#div1
"
)
.
html
(
txt
)
;
}
)
;
Try it »
jQuery innerWidth() and innerHeight() methods
The innerWidth() method returns the width of an element (including padding).
The innerHeight() method returns the height of an element (including padding).
The following example returns the width and height of the specified
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
var
txt
=
"
"
;
txt
+=
"
div width, including padding:
"
- $
(
"
#div1
"
)
.
innerWidth
(
)
"
"
;
txt
+=
"
div height, including padding:
"
- $
(
"
#div1
"
)
.
innerHeight
(
)
; $
(
"
#div1
"
)
.
html
(
txt
)
;
}
)
;
Try it »
jQuery outerWidth() and outerHeight() methods
The outerWidth() method returns the width of an element (including padding and border).
The outerHeight() method returns the height of an element (including padding and border).
The following example returns the width and height of the specified
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
var
txt
=
"
"
;
txt
+=
"
div width, including padding and border:
"
- $
(
"
#div1
"
)
.
outerWidth
(
)
"
"
;
txt
+=
"
div height, including padding and border:
"
- $
(
"
#div1
"
)
.
outerHeight
(
)
; $
(
"
#div1
"
)
.
html
(
txt
)
;
}
)
;
Try it