Ok this might sound odd, but for some reason I am not able to dynamically attach select2() on selects that are being added to page later, after uses presses a button to add more selects..
I've been using jquery's .on() event with no problems before, but with selects I guess there is sowething different, idk.
This is my code:
$(document).on('focus','select[rel=multiselect]',function(event){
$(this).select2();
});
What it does is - select2 activates on <select>s ONLY after I click on that select element, initially they are just plain selects. And after I click on a select, it first show me a regular plain select with options, and then makes it a select2 select..
Any ideas?
You are right, it is more of a jQuery specific question. But the thing is that jQuery's event delagation function .on() doesn't want to work properly with .select2() .. it works with everything else fine, when adding elements on the fly .on() works for other libraries.. For some reason it doesn't work for .select2()
I thought this 'd be the best place to ask for help, as I am sure someone out there had fell into a similar situation when .seelct2() was added to dynamically created elements, and not only to elements that were present on the page in the first place, were in initial DOM.