title: Uncaught TypeError: Cannot read property 'top' of undefined - Jquery
body: <p>I apologize if this question has already asked. I tried a lot. but won't works. If i have the <code>.div1</code> its working fine. but i removed <code>.div1</code>. Console through error like below. How can solve this.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'top' of undefined</p>
  </blockquote>
  
  <p><strong><a href="http://jsfiddle.net/fykxh387/2/" rel="nofollow">JS Fiddle</a></strong></p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div class="div"&gt;Console error&lt;/div&gt;
  &lt;!-- &lt;div class="div1"&gt;Working&lt;/div&gt;--&gt;
  &lt;div class="div2"&gt;2&lt;/div&gt;
  </code></pre>
  
  <p><strong>JQuery</strong></p>
  
  <pre><code>function resize() {
  var position= $('.div1').offset();
  var top= position.top;
      var newtop = top + 60 + "px";
      $('.div2').css( {
          'top': newtop 
      });
  }
  
  $(window).resize(function(){
     resize();
  });
  
  window.onload = resize();
  </code></pre>
  
  <p><strong>CSS</strong></p>
  
  <pre><code>.div1
  {
      position:fixed;
      top: 40px;
  }
  .div2
  {
      position:fixed;
  }
  </code></pre>
  
  <p><strong><a href="http://jsfiddle.net/fykxh387/2/" rel="nofollow">JS Fiddle</a></strong></p>