diff --git a/jquery.auto-grow-input.js b/jquery.auto-grow-input.js index c59fc2e..ccd3ebb 100644 --- a/jquery.auto-grow-input.js +++ b/jquery.auto-grow-input.js @@ -10,6 +10,18 @@ var event = 'oninput' in document.createElement('input') ? 'input' : 'keydown'; $.fn.autoGrowInput = function(options){ + if (options === 'destroy') { + this.each(function() { + var input = $(this); + input.off(event + '.autogrow autogrow'); + var span = input.data("autogrowSpan"); + span.remove(); + input.data('autogrowSpan',''); + }); + + return this; + } + var o = $.extend({ maxWidth: 500, minWidth: 20, comfortZone: 0 }, options); this.each(function(){ @@ -38,6 +50,7 @@ else if (newWidth < o.minWidth) newWidth = o.minWidth; if (newWidth != input.width()) input.width(newWidth); }; + input.data("autogrowSpan", span); input.on(event+'.autogrow autogrow', check); // init on page load check();