Alternative for innerHTML?

前端 未结 12 809
遇见更好的自我
遇见更好的自我 2020-12-04 13:34

I\'m wondering if there\'s a way to change the text of anything in HTML without using innerHTML.

Reason I\'m asking is because it\'s kinda frowned upon by the W3C. I

12条回答
  •  情话喂你
    2020-12-04 14:00

    The better way of doing it is to use document.createTextNode. One of the main reasons for using this function instead of innerHTML is that all HTML character escaping will be taken care of for you whereas you would have to escape your string yourself if you were simply setting innerHTML.

提交回复
热议问题