Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Auto extending HTML text area
var thisInput =;
var $thisInput = $(thisInput);
var previousScrollHeight = $'previous-scroll-height');
if(previousScrollHeight === null || previousScrollHeight === undefined){ //first time
previousScrollHeight = thisInput.scrollHeight;
if(previousScrollHeight !== thisInput.scrollHeight){
$thisInput.css('height', 'auto' );
$thisInput.height( thisInput.scrollHeight );
$'previous-scroll-height', thisInput.scrollHeight);
<div id='canvas'>
<textarea id='ta'></textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment