Skip to content

Spot innerHTML vs textContent Issue

Find the Mistake Medium
workbench

Question

This code displays user input but has a security risk. What is wrong?

Code

                  const userInput = "<img src=x onerror=alert('xss')>";
const el = document.getElementById("output");
el.innerHTML = userInput;
                

Related Resources

Related Lessons

  • DOM

    Learn about innerHTML vs textContent.

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

← Back to topic