xxxxxxxxxx
var x = document.createElement("tag");
x.style.color = "red";
document.body.appendChild(x);
xxxxxxxxxx
let myElm = document.createElement("p"); // Create a new element
myElm.innerText = 'test'; // Change the text of the element
myElm.style.color = 'red'; // Change the text color of the element
document.body.appendChild(myElm); // Add the object to the DOM
xxxxxxxxxx
var newDiv = document.createElement("div");
document.body.appendChild(newDiv);
xxxxxxxxxx
// Create a new element
const newElement = document.createElement("div");
// Set attributes or properties of the element
newElement.id = "myElement";
newElement.className = "my-class";
newElement.textContent = "This is a dynamically created element";
// Append the element to the document body or any other parent element
document.body.appendChild(newElement);
xxxxxxxxxx
// Create a new <div> element
var newElement = document.createElement("div");
// Set attributes (if needed)
newElement.id = "myElement";
newElement.className = "myClass";
// Set inner HTML (if needed)
newElement.innerHTML = "This is a new element";
// Append the new element to an existing element in the document
document.getElementById("parentElement").appendChild(newElement);