jQuery innerWidth()

Introduction

Return the inner width of a <div> element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from www  . j  a  v a 2s .c  om*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    document.getElementById("demo").innerHTML = "Inner width of div: " + $("div").innerWidth();
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<div style="height:100px;width:300px;padding:10px;margin:3px;background-color:lightblue;">
</div><br>

<button>Display the inner width of div</button>
<p>innerWidth() - returns the inner width of an element (includes padding).</p>

</body>
</html>

The innerWidth() method returns the inner width of the first matched element.

The returned value includes padding, but not border and margin.

$(selector).innerWidth()



PreviousNext

Related