Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of textarea in jQuery

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?

like image 313
GONeale Avatar asked Jan 06 '09 06:01

GONeale


People also ask

How to set value of textarea jQuery?

To set or get the text value of input or textarea elements, use the . val() method. To get the value of a script element, use the . html() method."

Can textarea have value?

From the MDN documentation: " <textarea> does not support the value attribute".

How do I display textarea content in HTML?

Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.


1 Answers

Have you tried val?

$("textarea#ExampleMessage").val(result.exampleMessage); 
like image 51
enobrev Avatar answered Sep 28 '22 03:09

enobrev