JQuery text()
The .text()
method in JQuery is used to get or set the text content of an element.
Syntax
To get the text content of an element, you can use the following syntax:
$(selector).text();
To set the text content of an element, you can use the following syntax:
$(selector).text(content);
Use
The .text()
method is useful when you want to get or set the text content of an element on a web page. You can use this method to manipulate the text content of HTML elements, such as headings, paragraphs, and lists.
Example
Here is an example of using the .text()
method to get and set the text content of an HTML element: