Is there any major difference between innerHTML and using createTextNode to fill a span?

徘徊边缘 提交于 2019-11-27 21:52:25

Of course. createTextNode will escape any strings and show them as they are, while innerHTML 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 use textContent (or innerText for IE).

Yet I'd recommend createTextNode, because all browsers support it equally without any quirks.

My understanding is that certain manipulations of innerHTML remove all bound events, so using createTextNode is preferable.

Doing some research online, here's what I've found. This should cover it at a high level:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!