JavaScript Anexe texto à div
var div = document.getElementById('myElementID');
div.innerHTML += "Here is some more data appended";
Grepper
var div = document.getElementById('myElementID');
div.innerHTML += "Here is some more data appended";
/*adds a element directly to the document without needing a parent or
container*/
let addTag = document.createElement("html")
document.append(addTag)
//or
let addTag2 = document.createElement("p")
document.body.append(addTag2)
The ParentNode. append() method inserts a set of Node objects or DOMString objects after the last child of the ParentNode . ... append() allows you to also append DOMString objects, whereas Node. appendChild() only accepts Node objects.
const parent = document.createElement('div');
const child = document.createElement('p');
const appendValue = parent.append(child);
console.log(appendValue) // undefined
const appendChildValue = parent.appendChild(child);
console.log(appendChildValue) // <p><p>
var person = {
firstName: "john",
lastName: "doe",
age: 45,
placeOfBirth: "somewhere"
}
for(var key in person) {
var p = document.createElement("p");
p.innerHTML = person[key];
document.body.appendChild(p)
}