Файл: library/wysihtml5/src/dom/replace_with_child_nodes.js
Строк: 41
<?php
/**
* Takes an element, removes it and replaces it with it's childs
*
* @param {Object} node The node which to replace with it's child nodes
* @example
* <div id="foo">
* <span>hello</span>
* </div>
* <script>
* // Remove #foo and replace with it's children
* wysihtml5.dom.replaceWithChildNodes(document.getElementById("foo"));
* </script>
*/
wysihtml5.dom.replaceWithChildNodes = function(node) {
if (!node.parentNode) {
return;
}
if (!node.firstChild) {
node.parentNode.removeChild(node);
return;
}
var fragment = node.ownerDocument.createDocumentFragment();
while (node.firstChild) {
fragment.appendChild(node.firstChild);
}
node.parentNode.replaceChild(fragment, node);
node = fragment = null;
};
?>