Skip to content
Related Articles

Related Articles

jQuery | outerWidth() Method
  • Last Updated : 19 Feb, 2019
GeeksforGeeks - Summer Carnival Banner

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.




<!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>

Before Click on the button:

After Click on the button:



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




<!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>

Before Click on the button:

After Click on the button:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :