Dinamically remove options from dropdown

Hi,

I would like to remove all options from an already open dropdown. When I remove them by simply erasing the ‘

  • ’ elements, the position of the dropdown is badly placed, as the position absolute and the value of top remains the same.

    The particular case is in a multiple select2 with remote ajax source, with the option closeOnSelect: false. When I want to change the search value, if for instance I remove a letter from previous value, the previous options still remain in the dropbox, so I want to clear all of them and just show the ‘searching’ label.

    Thank you

  • Your post is missing some information (the name of the elements you are deleting), so it’s hard to advise you. However, here is the official documentation for programmatcially removing elements from a Select2: https://select2.org/programmatic-control/add-select-clear-items#clearing-selections.