Jquery – CSS set div ‘top’ with jquery from div ‘height’


I have a template with lots of absolute positioning, now my main text div has a dynamic height and I need a dynamic footer which follows after this.

I tried to set the top state of the footer div with the height value from the text div.

 <script type="text/javascript">

Unfortunately, Chrome Dev tools throws the error:

Uncaught TypeError: Object [object Object] has no method 'top'
(anonymous function)

So any idea or help for my problem?


So i tried

 $('#footer').css('top', $('#text').outerHeight() + 'px');

and it works well, is it possible to add some px to this top value?

Best Solution

You will need to set the css property 'top' on the #footer div, not call .top() on the div itself.

$("#footer").css('top', $("#text").height() + "px");

or along those lines