Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Created April 18, 2022 23:47
Show Gist options
  • Save tangoabcdelta/a005f219fbd983656f7ea93b2854afbb to your computer and use it in GitHub Desktop.
Save tangoabcdelta/a005f219fbd983656f7ea93b2854afbb to your computer and use it in GitHub Desktop.
How to decode HTML entities in JavaScript?
// 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