Reset textarea height in javascript

后端 未结 3 596
执笔经年
执笔经年 2021-01-14 07:13

I have a textarea (auto resizing) and I want to clear all of its contents including its height.

So far I\'ve tried:

document.getElementById(\'textare         


        
相关标签:
3条回答
  • 2021-01-14 07:45

    You could use setAttribute to reset style attribute added automatically during the resize :

    document.getElementById('reset').onclick = function(){
        var textarea = document.getElementById('target');
      
        textarea.setAttribute('style','');
        textarea.value = "";
    }
    <textarea id="target" rows="1" cols="10"></textarea>
    <br>
    <button id="reset">Reset</button>

    0 讨论(0)
  • 2021-01-14 08:00

    Try resetting the style:

    document.getElementById("textarea").style.height = "20px";
    
    0 讨论(0)
  • 2021-01-14 08:03

    Just a JQuery version, that I'm using when I close a modal on my project

    $("#jobURL").attr("style", "").val("")
    
    0 讨论(0)
提交回复
热议问题