-
-
Save cferdinandi/721e46b6090895b860241af01561cfb3 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>decodeHTML()</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<script> | |
/** | |
* Decode HTML entities from an encoded string | |
* https://stackoverflow.com/a/7394787/1293256 | |
* @param {String} html The encoded HTML string | |
* @return {String} A decoded HTML string | |
*/ | |
function decodeHTML (html) { | |
let txt = document.createElement('textarea'); | |
txt.innerHTML = html; | |
return txt.value; | |
} | |
// Returns "<p>In this course, you'll learn:</p>" | |
let decoded = decodeHTML('<p>In this course, you&rsquo;ll learn:</p>'); | |
console.log(decoded); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment