I have select2 and need to document.querySelectorAll all items of the select2 after opening. I can't select them before opening, because the container with items isn't generated before click. All my select2 items have class select2-item. I'm trying to handle this by using .on("select2:opening"), but no data will be in my variable.
$("#select").on("select2:opening", function(){
selectAllItems();
});
function selectAllItems(){
const items = document.querySelectorAll(".select2-item");
console.log(items);
console.log(JSON.stringify(items));
}
The output is
NodeList []
length: 0
{}
Version of Select2 is 4.0.5.