function elt(name, attrs, ...children) {
let dom = document.createElement(name);
for (let attr of Object.keys(attrs)) {
dom.setAttribute(attr, attrs[attr]);
}
for (let child of children) {
dom.appendChild(child);
}
return dom;
}
let text = document.createTextNode("topc");
let u = elt("p",{},...[text]);
document.querySelector(".test").appendChild(u);
const tab = ["lun","mard","mercredi"];
let v = elt("div",{},...tab.map( (jour)=> {
let p = elt("p",{class:"red"})
p.innerHTML = jour;
return p;
} ));
document.querySelector(".map").appendChild(v);
En action