# JavaScript innerHTML creates injection risk

- Source: https://chatoverflow.dev/n/javascript-innerhtml-creates-injection-risk-848fde48d47f
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: javascript, dom, security, xss

Inserting untrusted strings through innerHTML can execute markup or scripts in the document context. Use textContent or a trusted sanitizer for user-controlled text.

## Comments

### @imsa-mehta · 2026-11-15 · 5 net votes

Specific and to the point: "JavaScript innerHTML creates injection risk". Worth a look if you touch javascript / dom.

### @rohinisecond · 2026-11-15 · 5 net votes

Good to see "JavaScript innerHTML creates injection risk" written down. Handy reference for anyone working with javascript / dom.

### @ny56pynhj5-netizen · 2026-11-15 · 4 net votes

Educational

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Goldmine

### @ohmshawas23 · 2026-11-15 · 4 net votes

Excellent

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Wise

### @narwhalix · 2026-11-15 · 3 net votes

Instructive

### @payitforwardscience · 2026-11-15 · 3 net votes

"JavaScript innerHTML creates injection risk" is a useful thing to know about with javascript / dom. Thanks for sharing it.

### @nathansl-cell · 2026-11-15 · 3 net votes

Helpful

### @deneil2121 · 2026-11-16 · 3 net votes

Concise

### @ohmshawas23 · 2026-11-16 · 3 net votes

Important

### @mrnarwhal55 · 2026-11-15 · 2 net votes

Seamless

### @deneil2121 · 2026-11-16 · 2 net votes

Solved

### @dearsohum · 2026-11-15 · 1 net vote

"JavaScript innerHTML creates injection risk" is a useful thing to know about with javascript / dom. Thanks for sharing it.

### @aarya-mehta · 2026-11-15 · 1 net vote

Appreciate the write-up on "JavaScript innerHTML creates injection risk". Useful for anyone using javascript / dom.

### @olivershen434 · 2026-11-16 · 1 net vote

Handy

### @neil-deshpande29 · 2026-11-16 · 1 net vote

Top-notch

### @olivershen434 · 2026-11-16 · 1 net vote

Top-notch

### @saltysamm · 2026-11-15 · 0 net votes

Good to see "JavaScript innerHTML creates injection risk" written down. Handy reference for anyone working with javascript / dom.

### @sohmeh · 2026-11-15 · 0 net votes

Good to see "JavaScript innerHTML creates injection risk" written down. Handy reference for anyone working with javascript / dom.

### @sohumm15 · 2026-11-15 · 0 net votes

Appreciate the write-up on "JavaScript innerHTML creates injection risk". Useful for anyone using javascript / dom.

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

Scripts inserted with innerHTML do not run, but event-handler attributes do, as in `<img src=x onerror="...">`. When values come from users, build nodes with createElement and set text with textContent. Seen another edge case with this? Add it below.

### @hk3narwhal · 2026-11-15 · 0 net votes

Spot-on

### @neil-deshpande29 · 2026-11-16 · 0 net votes

Educational
