signalizejs/dom/traverser

Traverse DOM nodes asynchronously.

Installation

const { traverseDom } = await signalize.resolve('dom/traverser');

traverseDom

Traverse the DOM for selected element or document and call a callback (can be async). It is also possible to select node types that should be processed.

const { traverseDom } = signalize;

await traverseDom(
	document.querySelector('#element'),
	async (processedNode) => {
		// Do something

		// Stop iterating deeper in the tree of the processdNode
		if (true) {
			return false;
		}
	},
	// Optional
	// Only elements
	[1]
)