jQuery | outerWidth() Method

The outerWidth() Method in jQuery is used to return the value of outer width of an element which includes border & padding.

Syntax:

$(selector).outerWidth( includemargin )

Parameters: This method accepts single parameter includeMargin which is optional. It contains boolean value and used to specify whether the margin to be included or not. If includeMargin is set to true then margin included otherwise margin not included. By default the includeMargin set to false.

Example 1: This example display the outer width including margin.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        jQuery outerWidth() Method
    </title>
      
    <!-- Style to create box -->
    <style>
        .GFG {
            height: 200px;
            width: 350px;
            padding: 20px;
            margin: 3px;
            border: 3px solid green;
            background-color: lightgreen;
        }
    </style>
      
    <script src=
    </script>
      
    <!-- Script to display outerWidth of
        box including margin -->
    <script>
        $(document).ready(function() {
            $("button").click(function(){
                alert("Outer width of div: " 
                + $("div").outerWidth(true));
            });
        });
    </script>
</head>
  
<body>
      
    <button>outerwidth</button>
   
    <div class="GFG"></div>
  
</body>
  
</html>

chevron_right


Before Click on the button:

After Click on the button:

Example 2: This example display the outer width and does not include margin.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        jQuery outerWidth() Method
    </title>
      
    <!-- Style to create box -->
    <style>
        .GFG {
            height: 200px;
            width: 350px;
            padding: 20px;
            margin: 3px;
            border: 3px solid green;
            background-color: lightgreen;
        }
    </style>
      
    <script src=
    </script>
      
    <!-- Script to display outer width excluding margin -->
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                alert("Outer width of div: "
                + $("div").outerWidth());
            });
        });
    </script>
</head>
  
<body>
    <button>outerwidth</button>
   
    <div class = "GFG"></div>
   
</body>
</html>

chevron_right


Before Click on the button:

After Click on the button:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.