The title is pretty clear:
Is there any major difference between innerHTML and createTextNode (used with Append) to fill a span with text?
The title is pretty clear: Is there any major difference between innerHTML and createTextNode
Share
Of course.
createTextNodewill escape any strings and show them as they are, whileinnerHTMLcould render html-like strings into a DOM. If you don’t want that (unless you are sure the text contains no unescaped tags, e.g. when assigning a literal directly), you can usetextContent(orinnerTextfor IE).Yet I’d recommend
createTextNode, because all browsers support it equally without any quirks.