How to delete/remove all options from Select using only java


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

Ramognee Technologies pro premium priority asked 8 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 8 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: https://mdbootstrap.com/snippets/standard/grzegorz-bujanski/6093465#js-tab-view


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