user1975155
0
Q:

js create html element

var newDiv = document.createElement("div");
document.body.appendChild(newDiv);
11
<div id="div1">
  <p id="p1">This is a paragraph.</p>
  <p id="p2">This is another paragraph.</p>
</div>

<script>
var para = document.createElement("P");//make an p element
var node = document.createTextNode("This is new.");//create an innerhtml node
para.appendChild(node);//add the text to the p element

var element = document.getElementById("div1");//search the div1
var child = document.getElementById("p1");//search the first p element
element.insertBefore(para, child);//inserts the p element before the first paragraph
</script>
8

<div id="new">
<p id="p1">Tutorix</p>
<p id="p2">Tutorialspoint</p>
</div>
<script>
   var tag = document.createElement("p");
   var text = document.createTextNode("Tutorix is the best e-learning platform");
   tag.appendChild(text);
   var element = document.getElementById("new");
   element.appendChild(tag);
</script>
1
var img = document.createElement('img');
2

New to Communities?

Join the community