how to create element in javascript

JavaScript
let p = document.createElement('p');// A function to create elements in JS
function elementFactory(tag, text) {
    const el = document.createElement(tag);
    el.textContent = text;
    return el;
}

const someListItem = elementFactory("li", "some text"); 
var newElement = document.createElement("div"); //change div to your element
document.getElementById("myElement").appendChlid(newElement); //change myElement to your ALREADY EXISTING elementvar newDiv = document.createElement("div");
document.body.appendChild(newDiv);
Source

Also in JavaScript: