Skip to content

Instantly share code, notes, and snippets.

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