title: jQuery TypeError .offset is undefined
body: <p>have been trying to resolve this issue for many hours now and just cant figure it out.</p>
  
  <p>The environment is WordPress I am using a smooth scroll  function that will smooth scroll when I select a link on one page to a location on another page.</p>
  
  <p>the error I am getting is...</p>
  
  <p>TypeError: $(...).offset(...) is undefined</p>
  
  <p>the offending line of code is...</p>
  
  <pre><code>  scrollTop: $(elem).offset().top - headerHeight
  </code></pre>
  
  <p>My entire function is</p>
  
  <pre><code>jQuery(document).ready(function($) {
  
  var headerHeight = $('#header-wrap').height(); //When the header position is fixed
  
  $('a').click(function(){
      var hashEle = $(this).attr('href').split('#');
      if (hashEle.length &gt; 1) {
          if (hashEle[1] == 'top') {
              $('body, html').animate({
                  scrollTop: 0
              },800);
          } else {
          jQuery('body, html').animate({
              scrollTop: $('#'+ hashEle[1]).offset().top - headerHeight
          },800);
          }
      };
  })
  // find element from url
  hashname = window.location.hash.replace('#', '');
  elem = $('#' + hashname);
  if(hashname.length &gt; 1) {
      if(hashname == 'top') {
      $('body, html').animate({
              scrollTop: 0
          },500); 
      } else {
       $('body, html').animate({
              scrollTop: $(elem).offset().top - headerHeight
          },800);
   }
  };
  
   });
  </code></pre>
  
  <p>I am going crazy here, the code works fine but it is creating a conflict with WooCommerce and I would just like it not to throw an error. Can someone tell me why this is causing trouble, sorry for the newbi question!</p>