Skip to content

Instantly share code, notes, and snippets.

@DevShahidul
Created June 23, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevShahidul/24eff7258b21fac6f5771e927e0d11aa to your computer and use it in GitHub Desktop.
Save DevShahidul/24eff7258b21fac6f5771e927e0d11aa to your computer and use it in GitHub Desktop.
if($('#long-answer-box').length){
var textarea = document.querySelector('textarea');
textarea.addEventListener('keydown', autosize);
function autosize(){
var el = this;
setTimeout(function(){
el.style.cssText = 'height:auto; padding:0';
// for box-sizing other than "content-box" use:
// el.style.cssText = '-moz-box-sizing:content-box';
el.style.cssText = 'height:' + el.scrollHeight + 'px';
},0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment