开发者

How to: On keypress get textarea1 height and set height to textarea2

开发者 https://www.devze.com 2023-03-20 15:27 出处:网络
I have 2 textareas (textarea1 and textarea2). On textarea1 im using an expander. As you type the textarea expands. Now, what ever you type on the textarea1 is written on textarea2 but the second texta

I have 2 textareas (textarea1 and textarea2). On textarea1 im using an expander. As you type the textarea expands. Now, what ever you type on the textarea1 is written on textarea2 but the second textarea doesn't expand. I am looking something that would get the height from textarea1 as im typing and set it to textarea2. I would image it would be something like:

$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea1').val().height== ('#textarea2').height??

or

开发者_C百科
$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea2').attr('height', $('#textarea1').val().height);

None of those work.

Thanks alot


$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea2').css('height', $('#textarea1').height());


$("#textarea2").css("height", $("#textarea1").height() + "px");

That should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消