Reputation: 11
In my HTML:
< div id="textarea" style="overflow: scroll;"> < /div>
I'm trying to put a piece of javascript text which is set in var X
into the textarea but whenever I do
$("#textarea").val(X);
nothing happens, whereas if I do
$("#textarea").text(X);
the text version of X
shows up but not the formatting like \n
.
How can I get X
to show up properly in my textarea?
Upvotes: 1
Views: 193
Reputation: 144689
val()
is used for setting/getting the value of textarea
and input
elements, for div
elements you should use text()
or html()
. If you want to add HTML markup you should use html()
method instead:
Get/Set the HTML contents of the first element in the set of matched elements.
$("#textarea").html(X);
Upvotes: 3
Reputation: 55210
Naming a div
textarea won't make it a textarea
. Try this.
$("#textarea").html(X);
val
is for input, textarea etc...
Upvotes: 2