.outerWidth()
Get the current computed width for the first element in the set of matched elements, including padding and border.
Syntax
.outerWidth([includeMargin])
Parameters
includeMargin
- A Boolean indicating whether to include the element's margin in the calculation
Return value
The width of the element, along with left and right padding, border, and optionally margin, in pixels.
Description
If includeMargin is omitted or false, the padding and border are included in the calculation; if it's true, the margin is also included.
This method is not applicable to window and document objects; for these use .width() instead.
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type='text/javascript'>
$(document).ready(
function() {
alert(
'outerWidth: ' + $('div').outerWidth() + "\n" +
'outerHeight: ' + $('div').outerHeight()
);
}
);
</script>
<style type='text/css'>
div {
width: 200px;
height: 200px;
padding: 10px;
border: 1px solid rgb(200, 200, 200);
background: lightblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Outer width and height with margin
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type='text/javascript'>
$(document).ready(
function() {
alert(
'outerWidth: ' + $('div').outerWidth({margin: true}) + "\n" +
'outerHeight: ' + $('div').outerHeight({margin: true})
);
}
);
</script>
<style type='text/css'>
div {
width: 200px;
height: 200px;
padding: 10px;
border: 1px solid rgb(200, 200, 200);
background: lightblue;
margin: 10px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Home
JavaScript Book
jQuery
JavaScript Book
jQuery
DOM:
- jQuery DOM
- $("html tags"):generate code with the jQuery wrapper function.
- .add()
- .addClass()
- .after()
- .andSelf()
- .append()
- .appendTo()
- .attr()
- .before()
- .children()
- .clone()
- .closest()
- .contents()
- .css()
- .detach()
- .filter()
- .first()
- .get()
- .has()
- .hasClass()
- .height()
- .html()
- .index()
- .innerHeight()
- .innerWidth()
- .insertAfter()
- .insertBefore()
- .is()
- .last()
- .map()
- .next()
- .nextAll()
- .nextUntil()
- .not()
- .offset()
- .offsetParent()
- .outerHeight()
- .outerWidth()
- .parent()
- .parents()
- .parentsUntil()
- .position()
- .prepend()
- .prependTo()
- .prev()
- .prevAll()
- .prevUntil()
- .remove()
- .removeClass()
- .removeAttr()
- .replaceAll()
- .replaceWith()
- .siblings()
- .scrollLeft()
- .scrollTop()
- .slice()
- .text()
- .toArray()
- .toggleClass()
- .unwrap()
- .val()
- .wrap()
- .wrapAll()
- .wrapInner()
- .width()