text() in jQuery
Using this method we can retrieve all the text contents of each element including their descendants, or set the text contents of the matched elements.
This method cannot be used on form inputs or scripts.
- text - The text to set as the content of each matched element.
- index - Index position of the element in the set.
- currentTextString - The old text value.
text() method convert like below
< to <
> to >
Example 1 - get text
Example 2 - set text
Example 3 - get old text and set new text
Example 4 - Execution steps
Example 5 - Get drop down text and selected text
Difference between html() and text()
Using text() method it retrieves only the text from an element, but using html() method both the text as well as the HTML markup can be retrieved from the element.