Reputation:
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('textarea').value = '';
And :
document.getElementById('textarea').attribute('rows','1');
But both doesn't work.
EDIT :
I use autosize.js with this :
<textarea id="post" rows="1" title="Write something..." name="posttxt" placeholder="Write something..." role="textbox" autocomplete="off"></textarea>
Upvotes: 3
Views: 5583
Reputation: 542
Just a JQuery version, that I'm using when I close a modal on my project
$("#jobURL").attr("style", "").val("")
Upvotes: 0
Reputation: 167
Try resetting the style:
document.getElementById("textarea").style.height = "20px";
Upvotes: 0
Reputation: 67505
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>
Upvotes: 5