Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery container height() not calculated properly

$('.container').height(); gives the wrong value when it's child elements have spacing CSS attributes on 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 ?

like image 461
Britney Spears Avatar asked Nov 21 '25 14:11

Britney Spears


1 Answers

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.
like image 121
ShankarSangoli Avatar answered Nov 23 '25 02:11

ShankarSangoli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!