title: JavaScript - Cannot read property 'top' of null
body: <p>I have function that scrolls to a anchor position in a list</p>
  
  <pre><code>   function snapToAnchor(anchor) {
      $('#divProductScroll').scrollTop(0);
      var offset = $(anchor).offset().top - $('#divProductScroll').offset().top;
      $('#divProductScroll').scrollTop(offset);
      //$('#divProductScroll').animate({ scrollTop: offset }, 250);
  }
  </code></pre>
  
  <p>but this is giving me error some times</p>
  
  <p>saying <strong>Cannot read property 'top' of null</strong></p>
  
  <p>I am not so good with JavaScript</p>
  
  <p>Can any one help with this issue?</p>
  
  <p><strong>I found the Problem.</strong>
  <hr />
   This snapToAnchor function is in a dialog model, so second time when i hit this function, there is not list generated, that's why i have null value, so what i did is before firing this function, i recreate the modal and then step in to the function, now no scope of null.</p>