Topic: How to delete/remove all options from Select using only javascript
Ramognee Technologies pro premium priority asked 6 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 6 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
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- 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