append html text javascript code example

Example 1: javascript append to paragraph

// In the JS script

var parElement = document.getElementById("myPar");
var textToAdd = document.createTextNode("Text to be added");
parElement.appendChild(textToAdd);

//In the HTML file

<p id="myPar"></p>

Example 2: how to append in javascript

var list=[1, 2, 3, 4, 5];
list.push(6);
// .push allows you to add a value to the end of a list

Example 3: JavaScript append HTML

let app = document.querySelector('#app');
app.append('append() Text Demo');

console.log(app.textContent);