Getting and Setting Text Content - J Query

You need to get or set the text that is contained inside of an HTML element(s).


jQuery provides the text() method for getting and setting the text content of elements.In the following code, we use this method to set and then get the text value of the <p>element found in the HTML document:

Running this code in a browser will result in a browser alerting the content of the <p>element, which we set using the text() method and then retrieved using the text() method.

It’s important to remember that the text() method is not unlike html() except that the text() method will escape HTML (replace <and >with their HTML entities). This means that if you place tags inside of the text string passed to the text() method, it will convert these tags to their HTML entities (&lt; and &gt;).

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

J Query Topics