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

scimitar01 premium asked 1 year 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 ( at hr._addAnimatedClass ( at hr._startAnimation ( at HTMLHtmlElement. ( at HTMLHtmlElement.t (

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,

            // Base HTML Markup
            $el = $('<a />')
                    'href': '#header',
                    $('<i />')

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

Mateusz Lazaru staff answered 1 year ago

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

scimitar01 premium commented 1 year 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.


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



Specification of the issue

  • ForumUser: 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