How to get the height of the text inside of a textarea

后端 未结 8 1637
眼角桃花
眼角桃花 2020-12-05 10:02

I have a textarea with the the text Hello World. I would like to get the height of this text.

I\'ve tried to use:

var eleme         


        
8条回答
  •  醉话见心
    2020-12-05 10:46

    In jQuery there is no scrollHeight, so it needs a little workaround. the solution would be:

    var areaheight=$("textarea#element")[0].scrollHeight;
    $("#element").height(areaheight);
    

    or shorter:

    $("#element").height($("#element")[0].scrollHeight)
    

提交回复
热议问题