1// .innerHTML method is used to change the html contents of a DOM object
2document.getElementById("demo").innerHTML = "Paragraph changed!";
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>
1function createElement( str ) {
2 var frag = document.createDocumentFragment();
3
4 var elem = document.createElement('div');
5 elem.innerHTML = str;
6
7 while (elem.childNodes[0]) {
8 frag.appendChild(elem.childNodes[0]);
9 }
10 return frag;
11}
12