What the difference between text() and html() functions in jQuery ?
$(\"#div\").html(\'Linkhello\
Strange that no-one mentioned the Cross Site scripting prevention benefit of .text()
over .html()
(Although others have just mentioned that .text()
escapes the data).
It's always recommended to use .text()
when you want to update data in DOM which is just data / text for the user to see.
.html()
should be mostly used to get the HTML content within a div.