Refer : What is the difference between jQuery: text () and html ()? and Differences between .text () and .html () with escaped <and> characters
In fact, both look somewhat similar, but completely different, it depends on your use or intention, what you want to achieve,
Where to use:
- use .html () to work with containers with html elements.
- use .text () to change the text of elements that usually have separate open and close tags
jQuery.html() treats the string as HTML, jQuery.text() treats the content as text.
Unlike the .html (),. Text () method 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 HTML parsers in different browsers, the returned text may change in new characters and other empty space.)
Niranjan kala
source share