You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/1-document/05-basic-dom-node-properties/article.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -397,15 +397,15 @@ Compare the two:
397
397
<div id="elem2"></div>
398
398
399
399
<script>
400
-
let name = prompt("What's your name?", "<b>Winnie-the-pooh!</b>");
400
+
let name = prompt("What's your name?", "<b>Winnie-the-Pooh!</b>");
401
401
402
402
elem1.innerHTML = name;
403
403
elem2.textContent = name;
404
404
</script>
405
405
```
406
406
407
407
1. The first `<div>` gets the name "as HTML": all tags become tags, so we see the bold name.
408
-
2. The second `<div>` gets the name "as text", so we literally see `<b>Winnie-the-pooh!</b>`.
408
+
2. The second `<div>` gets the name "as text", so we literally see `<b>Winnie-the-Pooh!</b>`.
409
409
410
410
In most cases, we expect the text from a user, and want to treat it as text. We don't want unexpected HTML in our site. An assignment to `textContent` does exactly that.
0 commit comments