0

enter image description here

Please give a look on the above screenshot of Chrome console. Though 1st line of jQuery code should change the "Top Position" of "#footer" DIV to 1426px, jQuery("#footer").position().top is showing as 1401 only. Its Top is expected to 1426, but shown as 1401. Please let me know if you understand its underlying causes.

3
  • Try with .offset(), to get the position relative to the document. Commented Jun 15, 2014 at 7:39
  • 1
    Is your footer positioned absolute or relative? Commented Jun 15, 2014 at 9:36
  • Footer position property was not set. After defining it to "absolute", it has been solved. Commented Jun 16, 2014 at 5:12

3 Answers 3

1

It was solved! Explanation: The "position" CSS property of #footer element was not defined, so by default, it would become "static". To solve this issue, I had to change its "position" property to "absolute".

Sign up to request clarification or add additional context in comments.

Comments

0

.top only gives you number not unit. But top expects some unit px or em or %

So, do this:

jQuery('#footer').css("top", jQuery('#pager').position().top + 40 + "px");

3 Comments

No, it doesn't work for me. jQuery('#footer').css("top", $('#pager').position().top + "px") returns 1401px, though it is expected as 1426px.
yes, I checked. Though it should be jQuery("#footer").css("top", (jQuery("#pager").position().top + 40) + "px"). If you give a look on 1st line of console screenshot, you can see it returns 'Style="top: 1426px;".
Doesn't have to specify 'px', jQuery set it by it self. The problem is elsewhere. @Agilox can you provide the code or demo for this?
0

try this one:

$top=jQuery('#pager').css('top');
if($top.match(/^-/g)){
    $top= '-'+parseInt($top.replace(/\D/g,''));
}
else{
    $top= parseInt($top.replace(/\D/g,''));
    }
$top=$top+40
jQuery('#footer').css("top",  $top + "px");

or if you position the #pager element by margins, you have to use $top=jQuery('#pager').css('margin-top');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.