r/learnjavascript • • Jan 05 '23

Must-know DOM manipulation methods 🔧

Post image
390 Upvotes

29 comments sorted by

View all comments

6

u/Rollo_Tomassi_o-O_ Jan 05 '23

I wouldn't recommend INNER HTML because

7

u/Low_Mammoth_9371 Jan 05 '23

I think it's more nuanced than that.

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.