vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
13 lines (12 loc) • 342 B
JavaScript
import insertAfter from './insertAfter';
function findEmptyElm(elm) {
const child = elm?.firstElementChild;
return child ? findEmptyElm(child) : elm;
}
export default (elm, html) => {
if (html) {
const wrapElm = findEmptyElm(insertAfter(elm, html));
wrapElm?.appendChild(elm);
}
return elm;
};