Khalid Ahmed
Khalid Ahmed

Reputation: 17

Why do I get Uncaught ReferenceError: scrollToM is not defined?

I have this code to make one page :-

$(window).load(function() {
  function filterPath(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'');
  }

  $('a[href*=#]').each(function() {
    if ( filterPath(location.pathname) == filterPath(this.pathname)
        && location.hostname == this.hostname
        && this.hash.replace(/#/,'') ) {
            var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
            var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : true;
            if ($target) {
                var targetOffset = $target.offset().top + 50;
                $(this).click(function(e) {
                    e.preventDefault();
                    $('html, body').animate({scrollTop: targetOffset}, 1400);
                    var d = document.createElement("div");
                    d.style.height = "90%";
                    d.style.overflow = "hidden";
                    document.body.appendChild(d);
                    window.scrollTo(0,scrollToM);
                    setTimeout(function() {
                        d.parentNode.removeChild(d);
                    }, 10);
                    return false;
                 });
             }
         }
     });
});

There are show me this error :-

Uncaught ReferenceError: scrollToM is not defined

What is the solution

Upvotes: 0

Views: 369

Answers (1)

Avinash Babu
Avinash Babu

Reputation: 6252

You have used window.scrollTo(0,scrollToM); but I can't even see where you have defined the variable. Check if the variable scrollTom is defined.

Upvotes: 1

Related Questions