.filter(selectorOrFn)
Available on: InDomArray

Returns a new InDomArray collection containing only the InDom objects that their elements match a CSS selector or pass a predicate function.
The original collection is left untouched.

Parameters:
selectorOrFn {string | {(n: InDom, index: number, array: InDomArray) => boolean}} -  CSS selector to match against elements or predicate function; return true to include the item in the result.

Returns: {InDomArray} - New filtered collection (empty if nothing matches).

Example:
const exampleDivs = $a('.example>div');
exampleDivs.onEnter(n => n.addClass('opened'));

$1('body').append('<div id="test-filter">test filter</div>');
$id('test-filter').onClick((...args) => {
	// keep only .opened items
	const openedDivs = exampleDivs.filter('.opened');

	// keep items that contain at least one <a>
	const divsWithLinks = openedDivs.filter(n => $a('a', n).length > 0);

	// same as:
	const divsWithLinks2 = new InDomArray();
	openedDivs.each(n => {
		if ($a('a', n).length > 0) {
			divsWithLinks2.push(n);
		}
	});

});
Modern DOM Power
for TypeScript, ESM & Plain JS
3.8KB JavaScript library that simplifies DOM manipulation
with a clean, chainable API for events, data, inputs harvesting, and more.
Automatic Cleanup,
Leak-Proof by Design
Events and state are cleared when elements leave the DOM,
even if removal happens outside InDom.
Cleaner Code,
Better Ergonomics
Get the InDom object directly in callbacks.
One element, one instance.
Works With Your Existing Stack
Use InDom on its own or alongside any library or framework,
its architecture ensures a seamless integration.