Set value of textarea in jQuery

GONeale picture GONeale · Jan 6, 2009 · Viewed 956k times · Source

I am attempting to set a value in a textarea field using jquery with the following code:

$("textarea#ExampleMessage").attr("value", result.exampleMessage);

The issue is, once this code executes, it is not altering the text in the textarea?

However when performing an alert($("textarea#ExampleMessage").attr("value")) the newly set value is returned?

Answer

enobrev picture enobrev · Jan 6, 2009

Have you tried val?

$("textarea#ExampleMessage").val(result.exampleMessage);