Topic: How to delete/remove all options from Select using only javascript

Ramognee Technologies priority asked 2 months ago

I want to remove/delete all options from select using javascript (i.e., Empty select)

And need to re-initialize with new options

Currently using this code to delete

document.querySelectorAll('#mySelect option').forEach(option => option.remove())

but still, the first option is showing in select

Grzegorz Bujański staff answered 2 months ago

After removing the options, you need to reinit the component. I have prepared a snippet for you with an example of how to do it:

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 7.2.0
  • Device: PC
  • Browser: Chrome
  • OS: Kubuntu
  • Provided sample code: No
  • Provided link: No