Insert an element after or before other element
Insert after
Insert the ele element after the refEle element:
refEle.parentNode.insertBefore(ele, refEle.nextSibling);
// Or
refEle.insertAdjacentElement('afterend', ele);Insert before
Insert the ele element before the refEle element:
refEle.parentNode.insertBefore(ele, refEle);
// Or
refEle.insertAdjacentElement('beforebegin', ele);