Back to TOP jQuery - Uncaught TypeError: Can not read property 'top' of undefined

0

I have the script to go back to TOP. On the homepage of the site, it works perfectly, however, in the internal pages it does not go up and it presents the following error:

  

Uncaught TypeError: Can not read property 'top' of undefined

jQuery

$(document).ready(function () {
  'use strict';
  /* ========================================================================
     Fullscreen burger menu
   ========================================================================== */
  $(".menu-trigger, .mobilenav").click(function () {
    $(".mobilenav").fadeToggle(500);
  });
  $(".menu-trigger, .mobilenav").click(function () {
    $(".top-menu").toggleClass("top-animate");
    $(".mid-menu").toggleClass("mid-animate");
    $(".bottom-menu").toggleClass("bottom-animate");
  });

  /* ========================================================================
     On click menu item animate to the section
   ========================================================================== */
  $(".mobilenav li, .back-to-top").on('click', function() {
    var target = $(this).data('rel');
    var $target = $(target);
    $('html, body').stop().animate({
        'scrollTop': $target.offset().top
    }, 900, 'swing');
  });

The error refers to the following line:

'scrollTop': $target.offset().top

Where would I be wrong?

    
asked by anonymous 07.06.2016 / 18:05

0 answers