HOME > > > > >

.innerWidth()

.innerWidth()

戻り値

Integer
数値

jQueryオブジェクトが持つDOM要素の最初のDOM要素の幅を返す。paddingは含むがborderは含まれない。

windowやdocumentオブジェクトを対象にする場合は.width()を利用する。

サンプル

実行結果


ここの
幅は?

Javascript

  1. var str = 'window : ' + $(window).innerWidth() + '/' + $(window).width() + '<br />';
  2. str += 'document : ' + $(document).innerWidth() + '/' + $(document).width() + '<br />';
  3. str += 'jqTest : ' + $('.jqTest').innerWidth() + '/' + $('.jqTest').width() + '<br />';
  4. str += 'No Element : ' + $('.NoElement').innerWidth() + '/' + $('.NoElement').width();
  5. $('.jqTest .screen').append(str);
  6.  
  7. $('.jqTest .targetBox').css({
  8.     padding: 20,
  9.     margin: 20,
  10.     border: '20px solid #990000',
  11.     background: '#CCCCCC'
  12. }).click(function(){
  13.     alert('[innerWidth]' + $(this).innerWidth() + '[width]' + $(this).width());
  14. });

HTML

  1. <div class="jqTest">
  2.     <div class="screen"></div>
  3.     <hr />
  4.     <div class="targetBox">
  5.     ここの<br />
  6.     幅は?
  7.     </div>
  8. </div>