I want to apply select2 to a bunch of jquery elements on the page that all have the same class name but it looks like if i call select2() on an element that already has had
You can check if Select2 operations give and error or not with try..catch
. If there is an error thrown, that means that there is not Select2 in the element.
The downside is that this will still output an error in the browser console.
try {
$(obj).select2("close")
} catch(err) {
// No Select2 in the element
$(obj).select2({ width: "455px" });
}