Файл: library/wysihtml5/src/dom/rename_element.js
Строк: 51
<?php
/**
* Renames an element (eg. a <div> to a <p>) and keeps its childs
*
* @param {Element} element The list element which should be renamed
* @param {Element} newNodeName The desired tag name
*
* @example
* <!-- Assume the following dom: -->
* <ul id="list">
* <li>eminem</li>
* <li>dr. dre</li>
* <li>50 Cent</li>
* </ul>
*
* <script>
* wysihtml5.dom.renameElement(document.getElementById("list"), "ol");
* </script>
*
* <!-- Will result in: -->
* <ol>
* <li>eminem</li>
* <li>dr. dre</li>
* <li>50 Cent</li>
* </ol>
*/
wysihtml5.dom.renameElement = function(element, newNodeName) {
var newElement = element.ownerDocument.createElement(newNodeName),
firstChild;
while (firstChild = element.firstChild) {
newElement.appendChild(firstChild);
}
wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
element.parentNode.replaceChild(newElement, element);
return newElement;
};
?>