diff --git a/src/selectize.js b/src/selectize.js index f11553d0c..8497a7289 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -2049,6 +2049,11 @@ $.extend(Selectize.prototype, { self.$control_input.removeData('grow'); self.$input.removeData('selectize'); + if (--Selectize.count == 0 && Selectize.$testInput) { + Selectize.$testInput.remove(); + Selectize.$testInput = undefined; + } + $(window).off(eventNS); $(document).off(eventNS); $(document.body).off(eventNS); diff --git a/src/utils.js b/src/utils.js index 6a54d7657..a418c9565 100644 --- a/src/utils.js +++ b/src/utils.js @@ -235,16 +235,20 @@ var measureString = function(str, $parent) { return 0; } - var $test = $('').css({ - position: 'absolute', - top: -99999, - left: -99999, - width: 'auto', - padding: 0, - whiteSpace: 'pre' - }).text(str).appendTo('body'); - - transferStyles($parent, $test, [ + if (!Selectize.$testInput) { + Selectize.$testInput = $('').css({ + position: 'absolute', + top: -99999, + left: -99999, + width: 'auto', + padding: 0, + whiteSpace: 'pre' + }).appendTo('body'); + } + + Selectize.$testInput.text(str); + + transferStyles($parent, Selectize.$testInput, [ 'letterSpacing', 'fontSize', 'fontFamily', @@ -252,10 +256,7 @@ var measureString = function(str, $parent) { 'textTransform' ]); - var width = $test.width(); - $test.remove(); - - return width; + return Selectize.$testInput.width(); }; /**