开发者

jQuery container height() not calculated properly

开发者 https://www.devze.com 2023-03-18 21:26 出处:网络
$(\'.container\').height(); gives the wrong value when it\'s child elements have spacing CSS attributes on 开发者_Go百科it:

$('.container').height(); gives the wrong value when it's child elements have spacing CSS attributes on 开发者_Go百科it:

<div class="container">
  <div style="padding: 10px;">
      weiorng3poin4gr9p34ng9p34n5g934ng5o43ng534g
      <div style="margin: 20px; ">
         eiong349ng49ng934ng59p34n5g439g5
      </div>
  </div>

</div>

How can I get the correct height of .container ?


Does the container <div> have any padding/margin/border? If so, you can try this:

$(".container").outerHeight(true);//will consider margin and border width as well.
0

精彩评论

暂无评论...
验证码 换一张
取 消