1// .innerHTML method is used to change the html contents of a DOM object
2document.getElementById("demo").innerHTML = "Paragraph changed!";
1document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";
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>
1var itemtoReplaceContentOf = $('#regTitle');
2itemtoReplaceContentOf.html('');
3newcontent.appendTo(itemtoReplaceContentOf);
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