var RoundMe = { roundBox: function(element) { var className = element.className.split(" ")[0]; // Create the innermost slice and re-locate the element's nodes to it var inner = document.createElement("div"); inner.className = className + "Inner"; while (element.firstChild) inner.appendChild(element.firstChild); var inner1 = this.createNestedBoxes(className + "Inner"); inner1.firstChild.appendChild(inner); var topBox = this.createNestedBoxes(className + "Top"); var bottomBox = this.createNestedBoxes(className + "Bottom"); element.appendChild(topBox); element.appendChild(inner1); element.appendChild(bottomBox); }, createNestedBoxes: function(className) { var box1 = document.createElement("div"); box1.className = className + "1"; var box2 = document.createElement("div"); box2.className = className + "2"; box1.appendChild(box2); return box1; } };