Select2 Initialize selection after adding data to existing

In my select2 select, I need to add li after the document is ready, and after adding, how can I reinitialize select2. If I ever close and reopen the selection, the added data will be selected, but not immediately after the addition. How can I reinitialize it.

+5
source share
1 answer

You need to destroy select2 on these elements and then reinitialize it.

$("select").select2("destroy").select2(); 
+13
source

Source: https://habr.com/ru/post/1209519/


All Articles