(element, parent)
| 19 | * @return {HTMLElement} The element that was passed to this function. |
| 20 | */ |
| 21 | var 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 | |
| 54 | module.exports = AddToDOM; |
no outgoing calls
no test coverage detected
searching dependent graphs…