What the difference between text() and html() functions in jQuery ?
$(\"#div\").html(\'Linkhello\
Actually both do look somewhat similar but are quite different it depends on your usage or intention what you want to achieve ,
.html()
to operate on containers having html elements..text()
to modify text of elements usually having separate open and
closing tags.text()
method cannot be used on form inputs or scripts.
.val()
for input or textarea elements..html()
for value of a script element.Picking up html content from .text()
will convert the html tags into html entities.
.text()
can be used in both XML and HTML documents..html()
is only for html documents.Check this example on jsfiddle to see the differences in action