* Create a new element on document with specified tagName and attributes. * @param {!Document} doc * @param {string} tagName * @param {!Object } attributes * @param {?(string|!Node|!ArrayLike<!Node>|!Array<!Node>)=} content * @return {!Element} created element.
(doc, tagName, attributes, content)
| 3696 | * @return {!Element} created element. |
| 3697 | */ |
| 3698 | function createElement(doc, tagName, attributes, content) { |
| 3699 | const element = doc.createElement(tagName); |
| 3700 | addAttributesToElement(element, attributes); |
| 3701 | if (content != null) { |
| 3702 | if (typeof content == 'string') { |
| 3703 | element.textContent = content; |
| 3704 | } else if (content.nodeType) { |
| 3705 | element.appendChild(/** @type {!Node} */ (content)); |
| 3706 | } else if ('length' in content) { |
| 3707 | for (let i = 0; i < content.length; i++) { |
| 3708 | element.appendChild(content[i]); |
| 3709 | } |
| 3710 | } else { |
| 3711 | assert(false, 'Unsupported content: %s', content); |
| 3712 | } |
| 3713 | } |
| 3714 | return element; |
| 3715 | } |
| 3716 | |
| 3717 | /** |
| 3718 | * Removes the element. |
no test coverage detected