javascript inner html code example
Example 1: change innerhtml
document.getElementById("p1").innerHTML = "New text!";
Example 2: .innerhtml
document.getElementById("demo").innerHTML = "Paragraph changed!";
Example 3: javascript innerhtml
document.getElementById("example").innerHTML = "Paragraph changed!";
Example 4: js innerHTML
document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";
Example 5: innerHTML
document.getElementById("Test").innerHTML = "<h1>Test</h1>";
Example 6: execute js with innerhtml
<html>
<head>
<script>
function executer_script(monscript) {
var head = document.getElementsByTagName("head")[0];
var scr;
var d = document.getElementById('resultat');
d.innerHTML = monscript;
var scrajx = d.getElementsByTagName('script');
for(var i in scrajx) {
scr = document.createElement("script");
scr.type = "text/javascript";
scr.text = scrajx[i].text;
head.appendChild(scr);
}
}
</script>
</head>
<body>
<input type="button" value="test" onclick="executer_script('Mon html + du javascript <script>alert(\'test\');</script>');">
<div id="resultat"></div>
</body>
</html>