How to create new elements in HTML page using javascript

Manideepgoud
Posted by Manideepgoud under JavaScript category on | Points: 40 | Views : 163
We can create new element in HTML page using javascript, We have to create element and then we should append it to existing element.
 <div id="home">
<p>DotNetFunda</p>
<p>TechFunda</p>
</div>
<script>
var a = document.createElement("p");
var b = document.createTextNode("ITFunda");
a.appendChild(b);
var c = document.getElementById('home');
c.appendChild(a);
</script>

In the above code we have created two paragraphs with two values and in the script function we have created "element p" and created text for the "element p" and we are appending "a with b" and we are having var c with id as home to append "c with a" which creates Text for new paragraph as ITFunda.

OUTPUT

DotNetFunda
TechFunda
ITFunda

Comments or Responses

Login to post response