.filter(selectorOrFn)
Available on: InDomArrayReturns 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:
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);
}
});
});Next: Usage Info »