jQuery innerWidth()


innerWidth() method
The innerWidth() method returns the inner width of the FIRST matched element.As the image below illustrates, this method includes padding, but not border and margin.

Syntax

$(selector).innerWidth()



Related methods:
  • width() - Sets or returns the width of an element
  • height() - Sets or returns the height of an element
  • innerWidth() - Returns the width of an element (includes padding)
  • outerWidth() - Returns the width of an element (includes padding and border).
  • outerHeight() - Returns the height of an element (includes padding and border).
<!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("Inner width of div: " + $("div").innerWidth());
    });
});
</script>
</head>
<body>

<div style="height:160px;width:380px;padding:10px;margin:3px;border:1px solid blue;background-color:red;"></div><br>
<p><b>innerWidth()</b> - this method returns the inner width of an element (includes padding).</p>
<button>Display the inner width of div</button>


</body>
</html>