title: Jquery:Uncaught TypeError: Cannot read property 'top' of undefined
body: <p>I'm having above error though this Jquery function is working fine.</p>
  
  <p>Html:</p>
  
  <pre><code>&lt;div id="context"&gt;
              &lt;h2&gt;Digital Library&lt;/h2&gt;
              &lt;a href="#" id="first" class="open"&gt;What is Digital Library?&lt;/a&gt;
              &lt;p id="one" style="display:none;"&gt;A digital library is a special library with a focused collection of digital objects that can include text, visual material, audio material, video material, stored as electronic media formats (as opposed to print, microform, or other media), along with means for organizing, storing, and retrieving the files and media contained in the library collection.&lt;/p&gt;&lt;br&gt;
              &lt;a href="#" id="second" class="open"&gt;How to search for specific ebook?&lt;/a&gt;
              &lt;p id="two" style="display:none;"&gt;To search an ebook, you just need to search for your desire ebook in below text boxes.When you click on search, a table with relevant results will show up.&lt;/p&gt;&lt;br&gt;
              &lt;a href="#" id="third" class="open"&gt;How to download ebook?&lt;/a&gt;
              &lt;p id="three" style="display:none;"&gt;To download an ebook you just need to click on download link, in the table results&lt;/p&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Jquery:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).on('click','.open', function(event) {
      event.preventDefault();
      var target = "#" + this.getAttribute('#context');
      $('html, body').animate({
          scrollTop: $(target).offset().top
      }, 2000);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>But because of this there is a link that is not opening.</p>
  
  <p>Html:</p>
  
  <pre><code>&lt;ul class="dropdown-menu ebook"&gt;
                  &lt;li&gt;&lt;a href="ebook.php"&gt;Ebooks&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="research.php"&gt;Research Journal&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I've already checked link spelling and other aspects but can't find any solution. Please help me! Thank you </p>