Saturday, November 12, 2011

how to get outerwidth of div - jquery

The outerWidth( [margin] ) method gets the outer width including padding and border for the first matched element.

.outerWidth( [includeMargin] )

includeMargin : A Boolean indicating whether to include the element’s margin in the calculation.

This method is not applicable to window and document objects; for these, use .width() instead.

<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('div').text('outerWidth: ' + $('div').outerWidth() );
<style type='text/css'>
div {width: 200px;height: 200px;padding: 10px;
border: 1px solid #ccc;background: #f0f0f0;}

No comments: