- 21.9k
- 6
- 63
- 80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute<title>Decode test<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').setAttribute('title',title theValue);= 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>.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute test</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').setAttribute('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>.
<!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>.
- 21.9k
- 6
- 63
- 80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute test</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
function html_entity_decode(str) {
var tap = document.createElement("textarea""p");
tap.innerHTML = str.replace(/</g,"<").replace(/>/g,">");
return tap.value;innerHTML;
}
var theValue = html_entity_decode('A → B');
document.getElementById('formula').setAttribute('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 innerHTMLandvalue of a <textarea>.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute test</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
function html_entity_decode(str) {
var ta = document.createElement("textarea");
ta.innerHTML = str.replace(/</g,"<").replace(/>/g,">");
return ta.value;
}
var theValue = html_entity_decode('A → B');
document.getElementById('formula').setAttribute('title', theValue);
</script>
</body>
</html>
Credits to The JavaScript Source.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute test</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').setAttribute('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 innerHTMLandvalue of a <textarea>.
You'll have to use the encoding a document is encoded in. E.g. UTF-8:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTFcharset="utf-8">
<title>setAttribute test</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
function html_entity_decode(str) {
var ta = document.getElementByIdcreateElement('formula'"textarea");
ta.setAttributeinnerHTML = str.replace('title'/</g,"<").replace(/>/g,">");
return ta.value;
}
var theValue = html_entity_decode('A →→ B');
document.getElementById('formula').setAttribute('title', theValue);
</script>
</body>
</html>
Credits to The JavaScript Source .
You'll have to use the encoding a document is encoded in. E.g. UTF-8:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>setAttribute test</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
document.getElementById('formula').setAttribute('title', 'A → B');
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setAttribute test</title>
</head>
<body>
<img id="formula" src="vote-arrow-up-on.png" alt="A → C">
<script>
function html_entity_decode(str) {
var ta = document.createElement("textarea");
ta.innerHTML = str.replace(/</g,"<").replace(/>/g,">");
return ta.value;
}
var theValue = html_entity_decode('A → B');
document.getElementById('formula').setAttribute('title', theValue);
</script>
</body>
</html>
Credits to The JavaScript Source .