Skip to content

Instantly share code, notes, and snippets.

@smunchi
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save smunchi/7eb1b2ac7bf612911f4f to your computer and use it in GitHub Desktop.

Select an option

Save smunchi/7eb1b2ac7bf612911f4f to your computer and use it in GitHub Desktop.
Textarea autogrow with jQuery
Here is a simple textarea:
<textarea name="content" id="content" class="form-control"></textarea>
Textarea will be expandable based on content height and also for content pasting.
$('textarea#content').on('keyup input', function() {
resizeTextarea(this);
});
function resizeTextarea(obj) {
var offset = obj.offsetHeight - obj.clientHeight;
$(obj).css('height', 'auto').css('height', obj.scrollHeight + offset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment