// main div child of body const mainDoc = document.getElementById("main"); //---------------------------------------------- const newElementDom = (element, where) => { // create element you want (div, span, p etc...) here is element parameters const newDiv = document.createElement(element); // add class in your element newDiv.classList.add("custom-class"); // add your element as child of where parameters (here is mainDoc variable) where.appendChild(newDiv); return newDiv; }; //------------------------------------------- // i creat div into another div called maindoc let div1 = newElementDom("div", mainDoc); // i creat div into another div called maindoc let div2 = newElementDom("div", mainDoc); console.log("nex", mainDoc); // i add custom css into both div div1.style.cssText = ` width: 500px; height: 500px; background: red; `; div2.style.cssText = ` width: 500px; height: 500px; background: red; `; 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 DOMvar newDiv = document.createElement("div"); document.body.appendChild(newDiv);// 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);const box = document.createElement("div"); box.id = "box"; document.body.appendChild(box);// 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);