Winnie Pooh case... : )
This commit is contained in:
parent
ac289950ea
commit
54df94da3d
1 changed files with 2 additions and 2 deletions
|
@ -397,7 +397,7 @@ Compare the two:
|
||||||
<div id="elem2"></div>
|
<div id="elem2"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let name = prompt("What's your name?", "<b>Winnie-the-pooh!</b>");
|
let name = prompt("What's your name?", "<b>Winnie-the-Pooh!</b>");
|
||||||
|
|
||||||
elem1.innerHTML = name;
|
elem1.innerHTML = name;
|
||||||
elem2.textContent = name;
|
elem2.textContent = name;
|
||||||
|
@ -405,7 +405,7 @@ Compare the two:
|
||||||
```
|
```
|
||||||
|
|
||||||
1. The first `<div>` gets the name "as HTML": all tags become tags, so we see the bold name.
|
1. The first `<div>` gets the name "as HTML": all tags become tags, so we see the bold name.
|
||||||
2. The second `<div>` gets the name "as text", so we literally see `<b>Winnie-the-pooh!</b>`.
|
2. The second `<div>` gets the name "as text", so we literally see `<b>Winnie-the-Pooh!</b>`.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue