jQuery Get Set Textarea text value


jQuery Get Set Textarea text value : We can use $(selector).val() method to get and set the textarea value. Here in this tutorial we are going to explain both set and get the textarea text using jquery val method. We will also create demo for both set and get methods.


jQuery Get Set Textarea text value

You can get and set textarea value as below –

Get Textarea text

If you want to get the text of the textarea you can use the below method –

jQuery Get Set Textarea text value: Get Text / Value Example

<script type="text/javascript">
function getTextareaVal(){
var text = $('#myTextarea').val();
alert(text);
}
</script>

Try it »

If you run the above example it will give you the content of the textarea.

Set Textarea text

If you want to set the text of the textarea you can set text value as following –

jQuery Get Set Textarea text value: Get Text / Value Example

<script type="text/javascript">
function setTextareaVal(){
var text = "New Text";
$('#myTextarea').val(text);
}
</script>

Try it »

If you run the above example it will set the given content in the textarea. The output of the above example will be something like this-

jQuery Get Set Textarea text value: Get Text / Value Example


Advertisements

Add Comment

📖 Read More