Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

How can I check if this element exists to prevent property of undefinmed error

$
0
0

I'm getting a jquery error : Uncaught TypeError: Cannot read property 'top' of undefined

I am assuming I have to add a check to my code but it still gives the error. I'm wondering how to add the check properly

jquery:

  var topOfElement = $('.references-list-container-outer').offset().top;

  $(window).scroll(function () {
    if ($(window).scrollTop() > topOfElement) {
      $('.article-nav-spotlight-chylers-page').fadeOut();
    } else {
      $('.article-nav-spotlight-chylers-page').fadeIn();
    }
  });

Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>