<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get Outer-Width and Outer-Height of an Element including Margin</title> <style> #box{ width: 300px; height: 200px; padding: 25px; text-align: justify; border: 10px solid #c6b51a; background: #f0e68c; margin: 15px; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var divWidth = $("#box").outerWidth(true); var divHeight = $("#box").outerHeight(true); $("#result").html("Outer Width: " + divWidth + ", " + "Outer Height: " + divHeight); }); }); </script> </head> <body> <div id="box">In a similar fashion, you have the ability to establish the inner width and height of an element by furnishing a value as a parameter to the innerWidth() and innerHeight() methods. These methods solely modify the width or height of the element's content region to align with the specified value.</div> <button type="button">Get outerWidth and outerHeight with margin</button> <p id="result"></p> <hr> <p><strong>Note:</strong>The jQuery function <b>outerWidth(true)</b> accounts for the CSS attributes (<b>width</b> + <b>padding-left</b> + <b>padding-right</b> + <b>border-left</b> + <b>border-right</b> + <b>margin-left</b> + <b>margin-right</b>), while <b>outerHeight(true)</b> considers (<b>height</b> + <b>padding-top</b> + <b>padding-bottom</b> + <b>border-top</b> + <b>border-bottom</b> + <b>margin-top</b> + <b>margin-bottom</b>).</p> </body> </html>