MCPcopy
hub / github.com/ampproject/amphtml / createElement

Function createElement

third_party/subscriptions-project/swg.js:3698–3715  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

3696 * @return {!Element} created element.
3697 */
3698function 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.

Callers 12

injectStyleSheetFunction · 0.70
constructorMethod · 0.70
constructorMethod · 0.70
constructorMethod · 0.70
initMethod · 0.70
createMethod · 0.70
constructorMethod · 0.70
constructorMethod · 0.70
buildIframe_Method · 0.70
constructorMethod · 0.70
pre_Method · 0.70

Calls 2

addAttributesToElementFunction · 0.70
assertFunction · 0.70

Tested by

no test coverage detected