A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

How to Set Value of Textarea in jQuery
Q:

How to Set Value of Textarea in jQuery

0

How to Set Value of Textarea in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery val() Method

You can simply use the val() method to set the value of a textarea dynamically using jQuery.

Let's try out the following example to understand how it basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Set Textarea Value</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        var textContent = "The quick brown fox jumps over the lazy dog.";
        $("button").click(function(){
            $("#myTextarea").val(textContent);
        });
    });
</script>
</head>
<body>
    <textarea id="myTextarea" rows="3" cols="50"></textarea>
    <br>
    <button type="button">Set Textarea Value</button>
</body> 
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now