(element)
| 17 | * @return {HTMLElement} The DOM element matching the given ID or node reference, or `document.body` if no valid target was found. |
| 18 | */ |
| 19 | var GetTarget = function (element) |
| 20 | { |
| 21 | var target; |
| 22 | |
| 23 | if (element !== '') |
| 24 | { |
| 25 | if (typeof element === 'string') |
| 26 | { |
| 27 | // Hopefully an element ID |
| 28 | target = document.getElementById(element); |
| 29 | } |
| 30 | else if (element && element.nodeType === 1) |
| 31 | { |
| 32 | // Quick test for a HTMLElement |
| 33 | target = element; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Fallback to the document body. Covers an invalid ID and a non HTMLElement object. |
| 38 | if (!target) |
| 39 | { |
| 40 | // Use the full window |
| 41 | target = document.body; |
| 42 | } |
| 43 | |
| 44 | return target; |
| 45 | }; |
| 46 | |
| 47 | module.exports = GetTarget; |
no outgoing calls
no test coverage detected
searching dependent graphs…