jquery - Get height of all children and apply it to parent -


I'm trying to calculate the height of "height: auto" div and then I have implemented this for Div:

  Function Center (divName) {$ (": Animated"). promise (). Done (function () {var totalHeight = 0; $ (divName)). children (). Each (function () {warning (totalheat); total hat + = $ (this). Hat ();}); $ (DivName) Css ("height", total height + "px"); }); } Center ("# frames_01");  

HTML:

  & lt; Div id = "frame_01" & gt; & Lt; H1 & gt; Text & lt; / H1> & Lt; H2 id = "next_frame_02" & gt; Continue & lt; / H2 & gt; & Lt; / Div & gt;  

To test the script, use alerts (totalHight); See, the problem is, the script first gives the kids with 0 px, but the other is correct.

I first thought that it would be because it starts computing before the animation is complete, so to get the height of the children first, I therefore have the $ (": animated"). Applied to .done (function () {) so that before waiting the animation is waiting to complete the animation.

But it was not resolved, why any suggestions?

Thanks in advance!

Edit:

What I am trying to achieve is that center is a div, but to do this, I want height of div. This is CSS:

  # frame_01 {text-align: center; Position: absolute; Margin: auto; Top: 0; Bottom: 0; Left: 0; Correct: 0;}  

height background color: red :

I call it .height () Resolved by changing .outerHeight (true)

Code:

  Function Center (divName) {$ (": Animated"). promise (). (Function () {var totalHeight = 0; $ (DivName). Child (). (Function () {alert (totalite); total hat = $ (this) .. oh (true);}); $ ( DivName). CSS ("height", total height + "px");}); } Center ("# frames_01");  

Comments