Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:28+00:00 2026-05-28T01:41:28+00:00

I use the following piece of code to make a div’s position fixed when

  • 0

I use the following piece of code to make a div’s position fixed when scrolled down (so it will stay in the window). It works perfectly fine, but in IE7 I get the error: offset().top is null or not an object.

$(document).ready(function(){
    var msie6 = $.browser == 'msie' && $.browser.version < 7;

    if (!msie6) {
    var top = $('#comment').offset().top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
        // what the y position of the scroll is
        var y = $(this).scrollTop();

        // whether that's below the form
        if (y >= top) {
            // if so, ad the fixed class
            $('#comment').addClass('fixed');
        } else {
            // otherwise remove it
            $('#comment').removeClass('fixed');
        }
     });
   }
});

Googling I found this (see bottom post by Earl Jenkins) http://api.jquery.com/offset/
In which he solves this particular error. But, jQuery & javascript beginner as I am, I don’t know how to implement this fix, because in his post he uses a fixed value (100), and in the piece of code above it doesn’t.

I tried to fix by doing this:

var fix = $('#comment').offset();
var top = fix.top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));

But it doesn’t do the trick. Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:41:28+00:00Added an answer on May 28, 2026 at 1:41 am

    I think that the problem you were running into was that you were accessing the top property of the window object when your #comment DIV wasn’t present.

    This problem isn’t well documented, but I’ve run into it before. I found a vague explanation of the cause at Dottoro.com’s reference to the window object.

    The window object is accessible from anywhere in the JavaScript code, so do not use variables with the same names as the members of the window object (although if you declare a variable with the same name as any member of the window object, the member of the window object stays accessible through the window object).

    The gist of it is that if you had changed your variable name from top to something else, the problem would’ve gone away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following piece of code to check out and then check in
I'm trying to write a piece of code that will do the following: Take
I use following piece of code to change printers port property. Problem is it
I have been trying to find ways to make the following piece of code
this following piece of code works, but it sort of makes the browser quirk
I want to use the following piece of code but it won't let me,
I use piece of code as following: list.OrderByDescending(x => x.Supporters.Sum(y=>y.Tokens)); (short explanation: any x
I use the following code to create countdowns in Javascript. n is the number
I use the following code to compile a cpp file to object file. g++
I use the following code try to create an array of string vectors, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.