MCPcopy Index your code
hub / github.com/phaserjs/phaser / AddToDOM

Function AddToDOM

src/dom/AddToDOM.js:21–52  ·  view source on GitHub ↗
(element, parent)

Source from the content-addressed store, hash-verified

19 * @return {HTMLElement} The element that was passed to this function.
20 */
21var AddToDOM = function (element, parent)
22{
23 var target;
24
25 if (parent)
26 {
27 if (typeof parent === 'string')
28 {
29 // Hopefully an element ID
30 target = document.getElementById(parent);
31 }
32 else if (typeof parent === 'object' && parent.nodeType === 1)
33 {
34 // Quick test for a HTMLElement
35 target = parent;
36 }
37 }
38 else if (element.parentElement || parent === null)
39 {
40 return element;
41 }
42
43 // Fallback, covers an invalid ID and a non HTMLElement object
44 if (!target)
45 {
46 target = document.body;
47 }
48
49 target.appendChild(element);
50
51 return element;
52};
53
54module.exports = AddToDOM;

Callers 3

CreateDOMContainerFunction · 0.85
Game.jsFile · 0.85
Text.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…