.top error in jQuery

0
$("#j_menu a").click(function(e) {
  var goto = $("#"+$(this).attr('href').replace('#','')+"");
    $('html, body').animate({
        scrollTop: goto.offset().top
    }, 'slow');
});

He accuses an error saying he can not read ".top" but on another site I'm building he acknowledged.

    
asked by anonymous 09.01.2018 / 17:26

1 answer

0

The .offset().top feature is called from jquery, so you should put the variable within $() thus getting $(goto).offset().top . To get position of the element only with javascript has this question here

    
09.01.2018 / 17:37