Reputation: 6762
I have a very unique problem while setting text to text area. While the text for exampleMessage is pulled from database it has the text with "\n" s inside it. when the text is setted to text area it shows on "this is" which is before first "\n" and truncates the next text after "\n".
weirdly when I click inside text area and click out again it shows the values. .val is fine to set value to textarea? .html has some issues when we dynamically get data. is .text suggestable?
<textarea id="ExampleMessage">
<textarea>
var result.result.exampleMessage ="this is \n a sample message \n by me";
$("textarea#ExampleMessage").val(result.exampleMessage);
Upvotes: 0
Views: 289
Reputation: 3799
I was not able to replicate the problem, but to answer your question... the best way to set/get the value of a textarea is the .val(). There is a discussion about that very topic in a thread if you want more information.
Just to test things, I used this:
$( document ).ready(function() {
var exampleMessage ="this is \n a sample message \n by me";
$("#ExampleMessage").text(exampleMessage);
console.log( exampleMessage );
});
and made an adjustment to your textarea. It could be that your textarea isn't big enough, but I don't think that is the cause.
<textarea id="ExampleMessage" cols="40" rows="6"></textarea>
Maybe this will help your issue.
Upvotes: 1