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
18 lines (17 loc) • 695 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const insertAfter_1 = __importDefault(require("./insertAfter"));
function findEmptyElm(elm) {
const child = elm === null || elm === void 0 ? void 0 : elm.firstElementChild;
return child ? findEmptyElm(child) : elm;
}
exports.default = (elm, html) => {
if (html) {
const wrapElm = findEmptyElm((0, insertAfter_1.default)(elm, html));
wrapElm === null || wrapElm === void 0 ? void 0 : wrapElm.appendChild(elm);
}
return elm;
};