jQuery .innerWidth() gets the current computed width for the first element

Syntax and Description

.innerWidth() gets the current computed width for the first element in the set of matched elements, including padding but not border.

Its Return value is the width of the element, including left and right padding, in pixels.

This method is not applicable to window and document objects, for these use .width() instead.

Get the inner width

The following sets the width for a div element first and gets its inner width afterwards.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--  w  w w .j  ava 2 s  . co m-->
             $("div").width(300);
             alert($("div").innerWidth());
        });
    </script>
    <style>
    div{
        width:200px;
        height:100px;
        overflow:auto;
    }
    h1 { width:1000px;height:1000px; }
  </style>

  </head>
  <body>
    <body>
       <div><h1>java2s.com</h1></div>
    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities