What the difference between text() and html() functions in jQuery ?
$(\"#div\").html(\'Linkhello\
Well in simple term.
html()-- to get inner html(html tags and text).
text()-- to get only text if present inside(only text)
text function set or retrieve the value as plain text, otherwise, HTML function set or retrieve the value as HTML tags to change or modify that. If you want to just change the content then use text(). But if you need to change the markup then you have to use hmtl().
It's a dummy answer for me after six years, Don't mind.
I think that the difference is to insert html tag
in text()
you html tag do not functions
$('#output').html('You are registered'+'<br>' +' '
+ 'Mister'+' ' + name+' ' + sourname ); }
output :
You are registered <br> Mister name sourname
replacing text()
with html()
output
You are registered
Mister name sourname
then the tag <br>
works in html()
The first example will actually embed HTML within the div
whereas the second example will escape the text by means of replacing element-related characters with their corresponding character entities so that it displays literally (i.e. the HTML will be displayed not rendered).