Reputation:
I have this code for textarea autoheight
function h(el) {
$(el).height(el.scrollHeight);
}
$('textarea').each(function () {
h(this); // works
//$(this).height($(this).scrollHeight); // doesn't work
});
$('textarea').on('input', function () {
h(this); // works
//$(this).height($(this).scrollHeight); // dosen't work
});
If I replace h(this)
with commented lines - they doesn't work.
What is the reason?
Upvotes: 0
Views: 24
Reputation: 671
In your group that doesn't work, you are converting this
to jQuery both on .height and .scrollHeight, but in your function h
, you only convert the el to jQuery on height
$('textarea').each(function () {
$(this).height(this.scrollHeight);
});
Upvotes: 1