What the difference between text() and html() functions in jQuery ?
$("#div").html('<a href="example.html">Link</a><b>hello</b>');
vs
$("#div").text('<a href="example.html">Link</a><b>hello</b>');
domjquery
What the difference between text() and html() functions in jQuery ?
$("#div").html('<a href="example.html">Link</a><b>hello</b>');
vs
$("#div").text('<a href="example.html">Link</a><b>hello</b>');
Best Answer
I think the difference is nearly self-explanatory. And it's super trivial to test.
jQuery.html()
treats the string as HTML,jQuery.text()
treats the content as textA difference that may not be so obvious is described in the jQuery API documentation
In the documentation for .html():
And in the documentation for .text():