diff --git a/src/js/jquery.select2.js b/src/js/jquery.select2.js index 4aeb22b8..b087c94b 100644 --- a/src/js/jquery.select2.js +++ b/src/js/jquery.select2.js @@ -24,18 +24,22 @@ define([ return this; } else if (typeof options === 'string') { - var instance = this.data('select2'); + var ret; - if (instance == null && window.console && console.error) { - console.error( - 'The select2(\'' + options + '\') method was called on an ' + - 'element that is not using Select2.' - ); - } + this.each(function () { + var instance = $(this).data('select2'); - var args = Array.prototype.slice.call(arguments, 1); + if (instance == null && window.console && console.error) { + console.error( + 'The select2(\'' + options + '\') method was called on an ' + + 'element that is not using Select2.' + ); + } - var ret = instance[options].apply(instance, args); + var args = Array.prototype.slice.call(arguments, 1); + + ret = instance[options].apply(instance, args); + }); // Check if we should be returning `this` if ($.inArray(options, thisMethods) > -1) {