Topic: Unselect mdb-select control using Javascript / Jquery

KenHartwigsen free asked 5 years ago

I want to clear the previously selection dropdown option that was selected from within a javascript function. How can I do this

MDBootstrap staff answered 3 years ago

Hi Eeesbk,

To restart our material select you can use attribute destroy: true, like this:

        destroy: true

This way whole select will be initialized again and all changes that user caused will be reverted.

Best Regards, Piotr

Eeesbk free answered 3 years ago

Hello. Im clear select value $(".active").removeClass(); and submit form... select not clear!! help pls

Jakub Strebeyko staff answered 5 years ago

Hi there Ken, Thanks for reaching out onto our forum. There seem to be numerous ways to proceed, depending on what specifically you mean by 'unselect'. In general, .material_select() function hides the select html element from sight, and what you're clicking on (the options) are span elements, children to lis within a newly-created, js-initiated ul element. And so, what selecting is in that context is granting these parent li elements the .active and .selected classes. The easiest way to unselect in that sense (aka not getting them selected) would be to create a function removing the classes right when they're added, like so: var select = $('.mdb-select'); select.material_select(); select.on("change", function(){ $(".active").removeClass(); }); Please let us know whether I read you correctly. With Best Regards, Kuba

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

  • User: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No