Uncaught TypeError: $(...).once is not a function

Created on 18 October 2023, about 1 year ago

After upgrading to D10 I get this error: "Uncaught TypeError: $(...).once is not a function".

The code in back_to_top.js:

(function ($) {
    Drupal.behaviors.backtotop = {
        attach: function (context, settings) {
            var exist = $('#backtotop').length;
            if (exist == 0) {
                $("body", context).once('backtotop').each(function () {
                    $('body').append("<button id='backtotop'>" + settings.back_to_top.back_to_top_button_text + "</button>");
                });
            }

            backToTop();
            $(window).scroll(function () {
                backToTop();
            });

            $('#backtotop', context).once('backtotop').each(function () {
                $(this).click(function () {
                    $("html, body").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function () {
                        $('html, body').stop();
                    });
                    // $('html,body').animate({scrollTop: 0}, 1200, 'easeOutQuart', function () {
                    $('html,body').animate({scrollTop: 0}, 350, 'linear', function () {
                        $("html, body").unbind("scroll mousedown DOMMouseScroll mousewheel keyup");
                    });
                    return false;
                });
            });

            /**
             * Hide show back to top links.
             */
            function backToTop() {
                if ($(window).scrollTop() > settings.back_to_top.back_to_top_button_trigger) {
                    $('#backtotop').fadeIn();
                } else {
                    $('#backtotop').fadeOut();
                }
            }
        }
    };
})(jQuery);
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024