val()
methodYou can use the jQuery val()
method to get or set the value of a <textarea>
element. Be sure to remove any trailing and leading whitespace, otherwise it may cause unexpected results.
The following example will get the value from the textarea and show you in an alert dialog box on click of the button when it is not equal ""
(i.e. not empty).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get Value from Textarea in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var comment = $.trim($("#comment").val());
if(comment != ""){
// Show alert dialog if value is not blank
alert(comment);
}
});
});
</script>
</head>
<body>
<textarea id="comment" rows="5" cols="50"></textarea>
<p><button type="button">Get Value</button></p>
<p><strong>Note:</strong> Type something in the textarea and click the button to see the result.</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to fire event on file select in jQuery
Use the jQuery change() method You ca...Firebase Phone Authentication With Invisible reCaptcha in Laravel5.6
Today, we are share with you how to impl...How to select an element with multiple classes with jQuery
Specify Class Names without Spaces in Be...Python String Zfill Method Example
Python zfill() is an inbuilt python stri...Laravel Eloquent Many to Many Relationship Tutorial with Example
While designing database structure, you...