You are here: Home / Topics / Write the code for dynamically inserting new components

Write the code for dynamically inserting new components

Filed under: JavaScript Interview Questions on 2022-07-06 10:09:22

With javascript you can insert content in your html document. This is the most popular feature of javascript programming. 

Here is the example of how you can insert element in your html document.

<html>

  <head>

  <title>inserting new components dynamically</title>

  <script type="text/javascript">    function addNode () { var newP = document. createElement("p");    var textNode = document.createTextNode(" This is other node");    newP.appendChild(textNode); document.getElementById("parent1").appendChild(newP); }

  </script>

  </head>

  <body>

 <p id="parent1">firstP<p> </body>

  </html>

About Author:
K
Kanak Sharma     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.