Last active
August 29, 2015 14:17
-
-
Save smunchi/7eb1b2ac7bf612911f4f to your computer and use it in GitHub Desktop.
Textarea autogrow with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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