value
Summary
Gets the content of a <textarea> element.
Property of dom/HTMLTextAreaElementdom/HTMLTextAreaElement
Syntax
var textAreaContent = textAreaElement.value;
textAreaElement.value = newTextAreaContent;
Return Value
Returns an object of type StringString
The content of the element, whether entered, existing or otherwise visible.
Examples
The following code uses this property to log the content of a <textarea>
and its length.
// Declaring the used variables first.
var textAreaList, textArea;
// Getting any <textarea> in the page
textAreaList = document.getElementsByTagName("textarea");
// Verifying there is at least one.
if (textAreaList.length) {
// Getting the first <textarea> in the page.
textArea = textAreaList[0];
// Logging the content of the first <textarea> in the page.
console.log("The content of the first textarea element is - " +
textArea.value);
// Logging the codepoint length of the
// content of the first <textarea> in the page.
console.log("The codepoint length of the content of the first textarea element is - " +
textArea.value.length);
}
Usage
Use this property to get the content of <textarea>.
Notes
In JavaScript/ECMAScript, the length property of this property can be used to determine the codepoint length of the content.
Related specifications
- Document Object Model (DOM) Level 1
- W3C Recommendation
- Document Object Model (DOM) Level 2 HTML
- W3C Recommendation
- W3C HTML5
- W3C Candidate Recommendation
- WHATWG HTML
- Living Standard
See also
Related articles
HTML
value