Home > Enterprise >  How to add text on top of a textarea element
How to add text on top of a textarea element

Time:11-13

I have a textarea element with some messages on it and a button. When I click the button It adds more text on it but the thing is that the text is adding at the bottom of the textarea and I want it added on top of it.

This is my code:

$('#textarea_id').append("New text added"); 

Could someone help me out? Thanks in advance.

CodePudding user response:

here's how to do it with just js. Get the original text and then append that to your new text. Finally, set the innerHTML of the textarea

let ta = document.getElementById('ta')

let s="some more text to append to top. "

ta.innerHTML= s   ta.innerHTML
#ta{
width:50%;
}
<textarea id='ta'>This is some text at the top</textarea>

  • Related