---
title: "How can add new elements dynamically in javascript?"  
description: "How can add new elements dynamically in javascript?"  
author: "Rahul Roi"  
published: 2021-03-16  
canonical: https://www.mindstick.com/interview/33783/how-can-add-new-elements-dynamically-in-javascript  
category: "javascript"  
tags: ["javascript", "scripting", "scripting language", "programming language"]  
reading_time: 1 minute  

---

# How can add new elements dynamically in javascript?

Where the javascript is a client-side as well as a server-side scripting language that can be inserted into HTML pages and is understood by web browsers. The JavaScript is also an Object-based Programming language.

```
<html>
<head>
<title>t1</title>
<script type="text/javascript">
 function addNode() { var newP = document.createElement("p");
 var textNode = document.createTextNode(" This is a new text node");
 newP.appendChild(textNode); document.getElementById("firstP").appendChild(newP); }
</script> </head>
<body> <p id="firstP">firstP<p> </body>
</html>
```

## Answers

### Answer by Rahul Roi

Where the javascript is a client-side as well as a server-side scripting language that can be inserted into HTML pages and is understood by web browsers. The JavaScript is also an Object-based Programming language.

```
<html>
<head>
<title>t1</title>
<script type="text/javascript">
 function addNode() { var newP = document.createElement("p");
 var textNode = document.createTextNode(" This is a new text node");
 newP.appendChild(textNode); document.getElementById("firstP").appendChild(newP); }
</script> </head>
<body> <p id="firstP">firstP<p> </body>
</html>
```


---

Original Source: https://www.mindstick.com/interview/33783/how-can-add-new-elements-dynamically-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
