Resize Textarea to fit Content
When users type and add or remove new lines the textarea re-sizes to fit the same number of lines
$('#content').on( 'change keyup keydown paste cut', 'textarea', function (){
$(this).height(0).height(this.scrollHeight);
}).find( 'textarea' ).change();
Check dat fiddle
http://jsfiddle.net/C8e4w/1/
Related protips:
jQuery: When to use $(document).ready() and when $(window).load()
Written by Mark Vaughn
Related protips
2 Responses
Excellent thanks :)
I have tweaked this a little to use it as an extension:
$.fn.extend({
autoresize: function () {
$(this).on('change keyup keydown paste cut', function () {
$(this).height(0).height(this.scrollHeight);
}).change();
}
});
$('#mytextarea').autoresize();
over 1 year ago
·
I signed up just tell you thank you for sharing, Mark. It was exactly what I needed. I added #content{overflow:hidden;} to get rid of the quick scroll bar that shows up when it resizes.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#