I'm using bootsrap-select, and because it has bug with the refresh method I have to destroy and re-render the selects:
$("#some_select").selectpicker('destroy');
$("#some_select").selectpicker('render');
After it I have a selector of jQuery to elements inside the bootsrap-select drop-down:
$(`.selectpicker:not(.${selector1}) a.dropdown-item${selector2}`).
The selector doesn't find matches anymore. If I place that line above the destroy part it does find.
Also it seem to work after destroying if I remove the last part of the selector:
a.dropdown-item${selector2}`
And it finds the correct elements. The part that's removed was added by ajax to load the dropdown items. Not sure if the AJAX could cause issues here together with the re-rendering method of bootsrap-select, but still the elements are seen in devtools.
If I console.log the selector matches before the destroy and then I click one of the matches then I get "Node cannot be found in the current page"
So it means the underlying Dom was destroyed. However I use the selector after the destroy part so it means the elements were re created by the time I use the selector (and can be seen in the devtools)
What can cause that and how can I make the selector find matches again?