2017-10-30 8 views
1

私はサイズ変更のdiv要素の幅を取得し、このようなコンソールにそれを表示しようとしています上のdiv要素の幅を取得します..それはjQueryのリサイズ

function matchHeight() { 
 
    var newHeight = jQuery("#container").height(); //where #grownDiv is what's growing 
 
\t console.log(newHeight); 
 
} 
 

 

 
jQuery(window).on('resize', function(){ 
 
matchHeight(); 
 
}); \t
#container{ 
 
    background:tan; 
 
    width:100%; 
 
    height:500px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="container"> 
 
Container Content 
 
</div>

をリフレッシュされていません私は間違っていますか?

+0

あなたは 'サイズ変更'イベントを引き起こすために何をしますか? –

答えて

3

おそらく、あなたは幅をつかみたいと思っていて、その代わりに高さをつかんでいます...サイズ変更では変わらないでしょう。

function matchWidth() { 
    var newWidth = jQuery("#container").width(); //where #grownDiv is what's growing 
    console.log(newWidth); 
} 


jQuery(window).on('resize', function(){ 
    matchWidth(); 
}); 
1

.height()と呼んでいます。試してみてくださいvar newWidth= jQuery("#container").width();

関連する問題