tags:

views:

475

answers:

2

Hi,

This question might sound subjective but I really do need to make a choise and in order for me to do that, I need some experienced voices.

Is there a resource, link or opinion that describes when and considering what issues to use the jquery's html(val), text(val) and append(content) for injecting content into an element?

are these comperable? or they are all designed for separate tasks?

regards,

kem

+8  A: 

Well, html(val) replaces the html content, text(val) inserts text (not tags) always while append(val) appends html content to the existing html content. They are different features html(val) being the most powerfull.

Miha Markic
in that case why replaceWith(content) exists? if html(val) already handles just that ?
Emin
replaceWith replaces the element, html() replaces the element's content.
Greg
A: 

text(val) == innerTEXT (only works on IE, so jQuery made it possible cross-browser)

html(val) == innerHTML (works like this DOM method)

append(val) == Node.appendChild


are these comperable?
well, you might compare in some cases html(val) to text(val),
but in some cases text() can't replace html().


or they are all designed for separate tasks?
Yes, they are designed for separate tasks, see some examples at visualjquery

vsync