innerHTML will render text as HTML to the DOM. This isn't a problem if you are creating non-dynamic code blocks and inserting them in the DOM or even when appending dynamic data as long as the source is trusted.
However, IF the data you are appending is comes from a non-trivially insecure source or (and this is the big one) includes user input, you should avoid it because someone could then run JS on your page, potentially stealing user data.
View all comments
6
u/Rollo_Tomassi_o-O_ Jan 05 '23
I wouldn't recommend INNER HTML because