Unable to get 'top' property from undefined or null reference (IE 11)

I am pretty inexperienced with JavaScript and am using a template. It is not possible to understand why this error appears in Internet Explorer. It works in any other browser.

$('.navbar a, .navbar li a, .brand, #footer li a, .more a, a.go-top')
  .bind('click', function(event) {
    var $anchor = $(this),
    scrollVal = $($anchor.attr('href')).offset().top - 60;

    if (scrollVal < 0) {
      scrollVal = 0;
    }

    $('[data-spy="scroll"]').each(function() {
      $(this).scrollspy('refresh');
    });

    $.scrollTo(scrollVal, {
      easing: 'easeInOutExpo',
      duration: 1500
    });

    event.preventDefault();
  });

Any ideas why this is happening?

+4
source share
1 answer

the error you see is on line 4

    scrollVal = $($anchor.attr('href')).offset().top - 60;

this is usually because you are trying to use object strength and undefined.

in your case $ ($ anchor.attr ('href')). offset () is probably undefined, you need to see if $ anchor is undefined or it does not have propierty href, so it cannot matter

(F12) .

, :

+2

Source: https://habr.com/ru/post/1543875/


All Articles