← Quiz: XSS: all 10 questions
Quiz: XSS · Question 7 of 10
Which line in plain JavaScript is safe for showing a user's comment?
Which line in plain JavaScript is safe for showing a user's comment?
- A.el.textContent = comment
- B.el.innerHTML = comment
- C.document.write(comment)
- D.el.outerHTML = comment
Answer & explanation
Correct answer: el.textContent = comment
textContent treats the value as text, never as HTML.
Can you get the rest right without peeking?
Take the timed Quiz: XSS quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →