1// .innerHTML method is used to change the html contents of a DOM object
2document.getElementById("demo").innerHTML = "Paragraph changed!";
1document.getElementById("myelement").innerHTML='<table id="mytable"><thead><tr><th>Row 1 - Column 1 - Header</th><th>Row 1 - Column 2 - Header</th></tr><thead><tr><td>Row 2 - Column 1</td><td>Row - 2 Column 2</td></tr><tr><td>Row 3 - Column 1</td><td>Row 3 - Column 2</td></tr></table>';
1<p id="demo" class="demo_class"></p>
2
3<script>
4//simple
5document.getElementById("demo").innerHTML = "hello World";
6
7//advance
8document.getElementById("demo").innerHTML = person("ahsan", "21");
9
10function person(name1, age1) {
11 return ("Your name is " + name1 + ". You're " + age1 + " years old.");
12}
13
14</script>
1<html>
2<head>
3
4<script>
5function executer_script(monscript) {
6 var head = document.getElementsByTagName("head")[0];
7 var scr;
8
9 var d = document.getElementById('resultat');
10 d.innerHTML = monscript;
11 var scrajx = d.getElementsByTagName('script');
12
13 for(var i in scrajx) {
14 scr = document.createElement("script");
15 scr.type = "text/javascript";
16 scr.text = scrajx[i].text;
17 head.appendChild(scr);
18 }
19}
20</script>
21
22</head>
23<body>
24
25<input type="button" value="test" onclick="executer_script('Mon html + du javascript <script>alert(\'test\');</script>');">
26
27<div id="resultat"></div>
28
29</body>
30</html>
31