Created
April 18, 2022 23:47
-
-
Save tangoabcdelta/a005f219fbd983656f7ea93b2854afbb to your computer and use it in GitHub Desktop.
How to decode HTML entities in JavaScript?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The native unescape or decodeURI or decodeURIComponent is not suitable for this job | |
// Instead, take the escaped HTML entity and set it as innerHTML | |
// Then, extract the innerText | |
// The complete list of HTML entities with their numbers and names can be found here. | |
// This page also includes full list of ASCII characters that can be represented in HTML. | |
// https://www.freeformatter.com/html-entities.html | |
d = document.createElement('div'); d.innerHTML = '!'; d.innerText; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment