title: $(this).offset() is null
body: <p>I have a problem here, i want the left hand side menu to slide down when it hits a certain point on the page and always stay at the top trying to do this with jQuery. Position fixed in css works but it doesnt stay at the top of the window when sliding down the page, leaves a big white gap. jQuery newbie here...</p>
  
  <p>I get this error; </p>
  
  <pre><code>$(this).offset() is null
  </code></pre>
  
  <p>Full code here</p>
  
  <pre><code>$(document).ready(function () {
  
  $(window).scroll(function (event) {
  
      var container = this;
  
      var msie7 = $.browser.msie &amp;&amp; $.browser.version &lt; 8;
  
      if (!msie7) {
          var top = $(this).offset().top - parseFloat($(this).css('margin-top').replace(/auto/, 0));
  
          $(window).scroll(function (event) {
  
              var y = $(this).scrollTop() + 10;
  
              if (y &gt;= top) {
                  $(container).find("#dvContentAlpha").addClass('LeftMenuFixed');
              } else {
                  $(container).find("#dvContentAlpha").removeClass('LeftMenuFixed');
              }
          });
      }
  });
  });
  </code></pre>
  
  <p>CSS</p>
  
  <pre><code>#dvContentAlpha
  {
  width: 145px;
  float: left;
  margin-right: 35px;
  position:fixed;
  }
  
  .LeftMenuFixed {
  float: left;
  font-weight: bold;
  position: fixed;
  top: 10px;
  width: 145px;
  }
  </code></pre>
  
  <p>Cannot read proprty top of null &lt;&lt; error message in google chrome inspect element</p>
  
  <p>do i need to set a value for top then? confused here.</p>
  
  <p>UPDATED:</p>
  
  <pre><code>$(document).ready(function () {
  
  $("div.homecontainer").each(function () {
      $(this).find("div.content-container").each(function () {
  
          var container = this;
  
          var msie7 = $.browser.msie &amp;&amp; $.browser.version &lt; 8;
  
          if (!msie7) {
              var top = $(this).offset().top - parseFloat($(this).css('margin-top').replace(/auto/, 0));
  
              $(window).scroll(function (event) {
  
                  var y = $(this).scrollTop() + 10;
  
                  if (y &gt;= top) {
                      $(container).find("#dvContentAlpha").addClass('div.LeftMenuFixed');
                  } else {
                         $(container).find("#dvContentAlpha").removeClass('div.LeftMenuFixed');
                  }
              });
          }
      });
  });
  });
  </code></pre>
  
  <p>Brings back no errors but doesnt slide down </p>
  
  <p>HTML is here</p>
  
  <pre><code>&lt;div class="homecontainer"&gt;
   &lt;div class="content-container"&gt;
      &lt;div id="dvContentAlpha"&gt;
          &lt;asp:BulletedList ID="blSideNavigation" runat="server" CssClass="leftnav-links"&gt;
          &lt;/asp:BulletedList&gt;
          &lt;a id="aContact" runat="server"&gt;&lt;img src="/Assets/Images/button-contact.jpg" alt="Contact Us" /&gt;&lt;/a&gt;
  
          &lt;div class="weatherwidget"&gt;
             &lt;!-- Yahoo! Weather Badge --&gt;&lt;iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" 
             scrolling="no" src="http://uk.weather.yahoo.com/badge/?id=28218&amp;u=c&amp;t=default&amp;l=vertical" height="255px" width="186px"&gt;
             &lt;/iframe&gt;&lt;noscript&gt;
             &lt;a href="http://uk.weather.yahoo.com/england/greater-manchester/manchester-28218/"&gt;Manchester Weather&lt;/a&gt; from 
             &lt;%--&lt;a href="http://uk.weather.yahoo.com"&gt;Yahoo! Weather&lt;/a&gt;--%&gt;&lt;/noscript&gt;&lt;!-- Yahoo! Weather Badge --&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  &lt;div id="dvContentBeta"&gt;
      &lt;div id="dvContentEncapsulation" runat="server"&gt;
          &lt;div id="dvContentEncapsulationInner" runat="server"&gt;
              &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt;
              &lt;/asp:ContentPlaceHolder&gt;
              &lt;div style="clear: both; float: none; height: 1px; overflow: hidden;"&gt;
                  &amp;nbsp;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="dvFooter"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>I found a much simpler solution to my problem, why couldnt this solution come out before i posted on here grrrr!
  For those that have similar problems this is what i used;</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(function () {
      var offset = $("#dvContentAlpha").offset();
      var topPadding = 15;
      $(window).scroll(function () {
          if ($(window).scrollTop() &gt; offset.top) {
              $("#dvContentAlpha").stop().animate({
                  marginTop: $(window).scrollTop() - offset.top + topPadding
              });
          } else {
              $("#dvContentAlpha").stop().animate({
                  marginTop: 0
              });
          };
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Works like a charm! </p>