/** * Enumerate through all the descendants including self. * @param e Element */ export function *childrenIterator(e: Element) { e = e.firstElementChild as HTMLElement; if (!e) { return; } for(;;) { yield e as HTMLElement; e = e.nextElementSibling; if (!e) { return; } } } childrenIterator.find = (e: HTMLElement, fx: (element: HTMLElement) => boolean) => { for (const element of childrenIterator(e)) { if (fx(element)) { return element; } } }