title: TypeError jQuery offset().top is undefined
body: <p>The Firefox debugger is showing a TypeError for a jQuery function aimed at sticking a navbar to the to the top of the page when a user scrolls and updating the class at the same time.</p>
  <p>The function is below.</p>
  <pre><code>$(window).scroll(function() {
      if ($(&quot;.navbar&quot;).offset().top&gt;30) {
          $(&quot;.navbar-fixed-top&quot;).addClass(&quot;sticky&quot;);
      }
      else {
          $(&quot;.navbar-fixed-top&quot;).removeClass(&quot;sticky&quot;);
      }
  });
  </code></pre>
  <p>The resulting error is this.</p>
  <blockquote>
  <p>Timestamp: 31/01/2014 10:01:04</p>
  <p>Error: TypeError: <code>$(...).offset(...)</code> is undefined</p>
  </blockquote>
  <p>I have looked about on SO for a similar example but can not translate the outcomes into a fix.  Any help would be greatly appreciated.</p>