help with adding and removing class

help with adding and removing class

I am trying to use some jquery in WordPress to add and remove a classname from a div. I have it working on a single page but for some reason, it will not work on the homepage. I have added an alert to give me the height of my div and when I click on a test page, i get the height and can tell just by looking at the page that the class is removed. When I go to the homepage, the alert function does not work and the class is not removed. I know for a fact that jquery is running on my site because It is used heavily. The only thing I can think of is that on my test page, there is only one class and on the homepage, there are 32 of them. Here is my code

  1. //get the height of the div
  2. var divh = $('.height').outerHeight();

  3. //get the div that I want to remove the class from
    var divscroll = $('.scroll');

  4. //This is an alert for testing purposes only. It gives me the height of my selected element
     alert(divh);

  5. r//emoving the class of "scroll" by default
            divscroll.removeClass('scroll');

  6. //if the height of the div is greater than 400 pixels, I want to remove the class; otherwise, add the 
  7. //class
            if(divh < 400){
                divscroll.removeClass('scroll');
            } else {
                divscroll.addClass('scroll');
            }
        });

I am not sure why this isn't working. I looked into using the each() function but I am having trouble understanding the code. I have added this code into the footer of my site.