I have the following code which inserts a new element of the same type over and over again to the parent element. I am new to JavaScript so was wondering if there was a better way of doing this. I apologise for the variable names, I'll get around to changing those later, just allows me to see the flow better. I'm trying to write this in pure js.
//Add a new lobby element
document.getElementById("addLobby").addEventListener("click", function(e) {
var layer1 = document.createElement("div");
layer1.setAttribute("class","col-wd-12 col-md-6 col-sm-4");
var layer2 = document.createElement("div");
layer2.setAttribute("class","col lobby");
var layer3 = document.createElement("div");
layer3.setAttribute("class","col lobby-infoPanel");
var layer3v2 = document.createElement("div");
layer3v2.setAttribute("class","overlay lobby-overlay");
var layer3v2v1 = document.createElement("a");
layer3v2v1.setAttribute("href","#");
var l3v2v1v1 = document.createElement("span");
l3v2v1v1.setAttribute("class", "overlay-options lobby-overlay-options");
var layer4 = document.createElement("div");
layer4.setAttribute("class","col lobby-info-count");
var layer4v2 = document.createElement("div");
layer4v2.setAttribute("class","col lobby-info-count lobby-info-users");
var l3v2v1v1Text = document.createTextNode("+");
var l4text = document.createTextNode("5/5");
var l4v2text = document.createTextNode("@User1");
layer4v2.appendChild(l4v2text);
layer4.appendChild(l4text);
layer3.appendChild(layer4);
layer3.appendChild(layer4v2);
l3v2v1v1.appendChild(l3v2v1v1Text);
layer3v2v1.appendChild(l3v2v1v1);
layer3v2.appendChild(layer3v2v1);
layer2.appendChild(layer3);
layer2.appendChild(layer3v2);
layer1.appendChild(layer2);
var lastNode = document.getElementById("addLobby").parentElement;
lastNode.parentElement.insertBefore(layer1, lastNode);
});