Learn all about the jQuery function .text().
.text() can be used in both XML and HTML documents. The result of the
.text() method is a string containing the combined text of all matched elements. (Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.) Consider the following HTML:
$( "div.demo-container" ).text() would produce the following result:
Demonstration Box list item 1 list item 2
.text() method cannot be used on form inputs or scripts. To set or get the text value of
textarea elements, use the
.val() method. To get the value of a script element, use the
As of jQuery 1.4, the
.text() method returns the value of text and CDATA nodes as well as element nodes.