UNPKG

@wordpress/dom

Version:
29 lines (27 loc) 772 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = replaceTag; var _assertIsDefined = require("../utils/assert-is-defined"); /** * Internal dependencies */ /** * Replaces the given node with a new node with the given tag name. * * @param {Element} node The node to replace * @param {string} tagName The new tag name. * * @return {Element} The new node. */ function replaceTag(node, tagName) { const newNode = node.ownerDocument.createElement(tagName); while (node.firstChild) { newNode.appendChild(node.firstChild); } (0, _assertIsDefined.assertIsDefined)(node.parentNode, 'node.parentNode'); node.parentNode.replaceChild(newNode, node); return newNode; } //# sourceMappingURL=replace-tag.js.map