1var paragraph = document.getElementById("p");
2
3paragraph.textContent += "This just got added";
1
2 var h = document.createElement("H1") // Create a <h1> element
3
4 var t = document.createTextNode("Hello World"); // Create a text node
5
6 h.appendChild(t); // Append the text to <h1>
1var p = document.getElementById("p")
2p.innerText = p.innerText+" And this is addon."
1<div id="mass">
2<p id="ph1">This is a paragraph.</p>
3<p id="ph2">This is another paragraph.</p>
4</div>
5
6<script>
7var head = document.createElement("h1");
8var node = document.createTextNode("New Heading.");
9head.appendChild(node);
10
11var ele = document.getElementById("mass");
12var child = document.getElementById("ph1");
13ele.insertBefore(head,child);
14//ele.append(head,child);
15
16Output :
17New Heading.
18This is a paragraph.
19This is another paragraph.