Topic: addClass interfering with 'scroll-to-top' function

scimitar01 premium asked 2 months ago


I'm using parts of a template with MDB and the 'scroll-to-top' chevron function to scroll to top of the page is not working. The first time I click nothing happens and nothing pops up in the console, but from the second click I get this error:

Uncaught DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided must not be empty. at Object.addClass (http://127.0.0.1:8000/static/js/mdb.min.js:19:75896) at hr._addAnimatedClass (http://127.0.0.1:8000/static/js/mdb.min.js:19:179258) at hr._startAnimation (http://127.0.0.1:8000/static/js/mdb.min.js:19:179472) at HTMLHtmlElement. (http://127.0.0.1:8000/static/js/mdb.min.js:19:181109) at HTMLHtmlElement.t (http://127.0.0.1:8000/static/js/mdb.min.js:19:73407)

Refering to 'manipulator.js' on line 99. This is the function on manipulator.js:

addClass(element, className) { if (element.classList.contains(className)) return; element.classList.add(className); },

This is a part of the scroll-to-top function that triggers the error:

        build: function() {
            var self = this,
                $el;

            // Base HTML Markup
            $el = $('<a />')
                .addClass(self.options.buttonClass)
                .attr({
                    'href': '#header',
                })
                .append(
                    $('<i />')
                    .addClass(self.options.iconClass)
            );

buttonClass is just 'scroll-to-top'. What can it be the problem?


mlazaru staff answered 2 months ago


What is the value of iconClass? Make sure you are not adding two classes at once.


scimitar01 premium commented 2 months ago

The 'scroll-to-top' consists of a element (with class scroll-to-top) with a element inside (which is an icon and has the class of 'fas fa-chevron-up'. So, two elements. Maybe this is interfering with the MDB 'manipulator.js' add function. Do you have any idea of how could I modify it in order to make it work?



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • User: Premium
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 6.0.1
  • Device: MacBook
  • Browser: Chrome
  • OS: macOS Monterey 15
  • Provided sample code: No
  • Provided link: Yes