formats.exposed/public/common/allChildrenOf.js

13 lines
289 B
JavaScript

// @ts-check
/**
* @param {HTMLElement} element
* @returns {Generator<HTMLElement, void, unknown>}
*/
export default function* allChildrenOf(element) {
yield element;
for (const child of element.children ?? []) {
yield* allChildrenOf(/** @type {HTMLElement} */ (child));
}
}