Demo: innerHTML vs. textContent
With text "hard-coded" in the web page
This isn't something you would normally do. It's just to illustrate the difference between these two ways of putting text between HTML tags.
Some sample text with HTML mark-up:
This is some text that contains HTML tags and symbols—like mdash.
- Sample text echoed with innerHTML:
- Sample text echoed with textContent:
With user input
- Your text echoed using a span's innerHTML:
No text yet...
- Your text echoed using a span's textContent:
No text yet...