Skip to main content Accessibility Feedback

childrenMatches.js

Get all direct descendant elements that match a test.

/*!
 * Get all direct descendant elements that match a test condition
 * (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
 * @param  {Node}   elem     The element to get direct descendants for
 * @param  {Function} callback The test condition
 * @return {Array}           The matching direct descendants
 */
function childrenMatches (elem, callback) {
	return Array.from(elem.children).filter(callback);
}