* Helper method to get an HTMLElement from various input types * * This is a core utility function that bridges jQuery objects with native DOM elements, * allowing our codebase to work with both paradigms while the Bootstrap 5 API requires * native DOM elements. * * @param elementOrSelector El
(elementOrSelector: string | HTMLElement | JQuery)
| 56 | * @returns HTMLElement or null |
| 57 | */ |
| 58 | function getElement(elementOrSelector: string | HTMLElement | JQuery): HTMLElement | null { |
| 59 | if (!elementOrSelector) return null; |
| 60 | |
| 61 | if (typeof elementOrSelector === 'string') { |
| 62 | return document.querySelector(elementOrSelector as string); |
| 63 | } |
| 64 | |
| 65 | if (elementOrSelector instanceof HTMLElement) { |
| 66 | return elementOrSelector; |
| 67 | } |
| 68 | |
| 69 | if (elementOrSelector instanceof $) { |
| 70 | return (elementOrSelector as JQuery)[0] as HTMLElement; |
| 71 | } |
| 72 | |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Private helper that sets an event handler on a single DOM element |
no outgoing calls
no test coverage detected