Why Is InnerHTML Used?

What is the disadvantage of using innerHTML in JavaScript?

There is no append support without reparsing the whole innerHTML.

This makes changing innerHTML directly very slow.

innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it..

What can I use instead of innerHTML?

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 .

What is the HTML tag under which one can write the JavaScript code?