The title is pretty clear:
Is there any major difference between innerHTML
and createTextNode
(used with Append
) to fill a span with text?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
My understanding is that certain manipulations of innerHTML remove all bound events, so using createTextNode is preferable.
Of course.
createTextNode
will escape any strings and show them as they are, whileinnerHTML
could 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
(orinnerText
for IE).Yet I'd recommend
createTextNode
, because all browsers support it equally without any quirks.