I have a text area. I can set the text of it with
$("#mytextarea").text("foo")
I can prepend to the text area like this:
$("#mytextarea").prepend("foo")
But I cannot prepend to the jquery text() object like this:
$("#mytextarea").text().prepend("foo")
The reason I want to do this is so that if my user gets me to prepend this text:
$("#mytextarea").prepend("<script>alert('lol i haxed uuu!')</script>")
...the script executes and I lose.
Help?
To add text to a textarea, access the value property on the element and set it to its current value plus the text to be appended, e.g. textarea. value += 'Appended text' . The value property can be used to get and set the content of a textarea element.
textarea is filled by user and user can only input texts in textarea . You can use drag and drop api to put image in textarea . Textarea is not a container tag hence not allow other tags inside it. It just provide multiple line input area to user.
You need to modify the val()
property:
$('#mytextarea').val(function(index, old) { return '...' + old; });
By the way, the correct way to get the contents of the textarea is to call val()
, not text()
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With