Updating multiple DIV based on the previous DIV

Updating multiple DIV based on the previous DIV

Hi!

I have the following HTML:
  1. <div id="box">
  2.         <div id="inner-new">
  3.                 content
  4.         </div>
  5.         <div id="new">
  6.                 new content
  7.         </div>
  8. </div>


This code block occurs several times. Sometime the first div ist just "inner" and the second div is missing.

Now I need to update the "new" DIV based on the height of the previous inner-new DIV. For one it works fine:

  1. var height = $('#inner-new').outerHeight();
  2. $('#new').css('margin-top', height*(-1)-30);
But how could I re-use this universally for all my boxes. It needs to check if the DIV "box" contains the DIV "inner-new" as first element, if that is true it need to update the DIV "new".

I tried several things with $('#box').each(function(i) { ... }); but couldn't come up with a solution.

Could someone please point me in the right direction?

Thanks.