Have a look at our insertAdjacentElement.html demo on Github (see the source code too.) Here we have a sequence of <div> elements inside a container. When one is clicked, it becomes selected and you can then press the Insert before and Insert after buttons to insert new divs before or after the selected element using insertAdjacentElement().