javascript - Why does .setAttribute not work with jQuery -


$(function () {      $('textarea').setattribute('style', 'height:' + ($('textarea').scrollheight) + 'px;');  });
<textarea>      very, long preloading text, mean vvveeerrryyy, vvveeerrryyy long one!  </textarea>

what doing wrong, please? double checked it, can't find wrong

  1. its attr() .
  2. change $('textarea').scrollheight $('textarea')[0].scrollheight.because return undefined
  3. setattribute() not defined function in jquery. , don't forget add jquery library in html.

$(function () {  $('textarea').attr('style', 'height:' + ($('textarea')[0].scrollheight) + 'px;');    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea>this very, long preloading text, mean vvveeerrryyy, vvveeerrryyy long one!</textarea>


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -