jQuery Style How to - Get Outer width and height with margin








Question

We would like to know how to get Outer width and height with margin.

Answer


<html>
  <head>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type='text/javascript'>
$(document).ready(<!--  w w w.  ja v a  2  s  .c o m-->
  function() {
    console.log(
      '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>

The code above is rendered as follows: