append element in javascript code example
Example 1: JavaScript append text to div
var div = document.getElementById('myElementID');
div.innerHTML += "Here is some more data appended";
Example 2: code for adding new elements in javascriipt js
<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>
Example 3: create and append element in javascript
var node = document.createElement("LI");
var textnode = document.createTextNode("Water");
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
Example 4: how to appendChild in the begin of the div javascript
var element = document.getElementById("div1");
element.insertBefore(para, element.firstChild);
Example 5: how to append in javascript
var list=[1, 2, 3, 4, 5];
list.push(6);
Example 6: JavaScript append HTML
let app = document.querySelector('#app');
app.append('append() Text Demo');
console.log(app.textContent);