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

Created on 18 October 2023, 9 months ago
Updated 14 December 2023, 7 months 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

RTBC

Version

3.0

Component

Code

Created by

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

Comments & Activities

Production build 0.69.0 2024