var element = document.getElementsByClassName("first")[0]; var wrapper = document.createElement("div"); element.parentNode.insertBefore(wrapper, element); wrapper.appendChild(element);