I have a textarea which is created after a successful AJAX call. It may contain quite a lot of text, and I would like it’s height to be automatically set so that the whole text would be visible without scrolling.
I am using autoResize plugin (http://james.padolsey.com/javascript/jquery-plugin-autoresize/), but it resizes inputs only on user input.
So, how do I resize a textarea so it would fit the text it contains?
Here is the code of the relevant function (var type can be ‘input’ or ‘textarea’)
function edit_create_input(name, value, type, autocomplete, autoresize)
{
var input=$('<' + type + ' class="edit-"' + name + ' name="'+name+'">').val(value);
if (autocomplete)
{
input.autocomplete("ajax.autosuggest.php",{'multiple':true});
}
if (autoresize)
{
input.autoResize();
}
return input;
In the
plugin sourcethere are 3 events on which theupdateSize()function is triggered:You should Trigger one of these after ajax loads the content:
Edit: according to your code
Note: using
.trigger()with the namespaced event is more convenient, since using.change()(which is also good) would trigger every change event binded to the object, not just the one you need.Update: old plugin source is not available anymore, I could only find a slightly modified version of the original here.