UNPKG

bigpipe-util

Version:

This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.

42 lines (33 loc) 784 B
function removeNode(node) { if (node.parentNode) { node.parentNode.removeChild(node); } } export default { prependContent(node, content) { node.insertAdjacentHTML("afterbegin", content); }, insertAfter(node, content) { node.insertAdjacentHTML("afterend", content); }, insertBefore(node, content) { node.insertAdjacentHTML("beforebegin", content); }, setContent(node, content) { node.innerHTML = content; }, appendContent(node, content) { node.insertAdjacentHTML("beforeend", content); }, replace(node, content) { node.outerHTML = content; }, remove(node) { removeNode(node); }, empty(node) { while (node.firstChild) { removeNode(node.firstChild); } } }