Showing posts with label outerWidth() method. Show all posts
Showing posts with label outerWidth() method. Show all posts

outerWidth() method


The outerWidth() method returns the outer width of the FIRST matched element. As the image below illustrates, this method includes padding and border.

Syntax


$(selector).outerWidth(includeMargin)




Example-

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        alert("Outer width of div: " + $("div").outerWidth());
    });
});
</script>
</head>
<body>
<div style="height:200px;width:600px;padding:10px;margin:3px;border:1px solid blue;background-color:yellow;"></div><br>
<p><b>outerWidth()</b> - this method returns the outer width of an element (includes padding and border).</p>
<button>Display the outer width of div</button>


</body>
</html>


Related methods:
  • width() - Sets or returns the width of an element
  • innerWidth() - Returns the width of an element (includes padding)
  • innerHeight() - Returns the height of an element (includes padding)
  • outerHeight() - Returns the height of an element (includes padding and border).
  • height() - Sets or returns the height of an element