Topic: Close dropdown on scroll

PerfectCamp priority asked 1 year ago

Does anyone know why I can't hide a dropdown using this code?

window.addEventListener('scroll', function() {
            // close any open dropdowns
            $('').each(function() {
                var dropdown = $(this).closest('.dropdown')[0];

The console shows an error: Uncaught TypeError: Cannot read properties of null (reading 'hide'). I wish I knew the jQuery way to hide a dropdown but can't see any docs showing how to control them via jQuery. Can anyone help? I can close the drop down's via getting rid of the show class but I would rather do it via the API so it fades out. Thanks!

Kamila Pieńkowska staff answered 1 year ago

You were trying to getInstance from the wrong element. I've prepared a snippet for you:

PerfectCamp priority answered 1 year ago

Thanks so much! Here is an updated simplified snippet using your solution.

window.addEventListener('scroll', function() {
            // close any open dropdowns
            $('').each(function() {

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: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 6.3.0
  • Device: PC
  • Browser: chrome
  • OS: win 11
  • Provided sample code: No
  • Provided link: No