<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Decode HTML entities using JavaScript</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
function html_entity_decode(str) {
var p = document.createElement("p");
p.innerHTML = str.replace(/</g,"<").replace(/>/g,">");
return p.innerHTML;
}
var theValue = html_entity_decode('A → B');
document.getElementById('formula').title = theValue;
</script>
</body>
</html>
Credits to The JavaScript Source.
EDIT: I changed the original code to only use innerHTML
on a <p>
element, instead of innerHTML
and value
of a <textarea>
.