From jQuery JavaScript Library
« Back to Attributes
text( )
Get the combined text contents of all matched elements.
The result is a string that contains the combined text contents of all matched elements. This method works on both HTML and XML documents. Cannot be used on input elements. For input field text use the
val attribute.
Examples:| Name | Type |
Find the text in the first paragraph (stripping out the html), then set the html of the last paragraph to show it is just text (the red bold is gone).
var str = $("p:first").text();
$("p:last").html(str);
text( val )
Set the text contents of all matched elements.
Similar to html(), but escapes HTML (replace "<" and ">" with their HTML entities). Cannot be used on input elements. For input field text use the
val attribute.
Arguments:| val | String | |
|---|
| The text value to set the contents of the element to. |
Examples:| Name | Type |
Add text to the paragraph (notice the bold tag is escaped).
$("p").text("<b>Some</b> new text.");