UNPKG

dom-children

Version:
21 lines (17 loc) 551 B
import is from 'dom-is'; /** * @param {Element} element - element to get children of * @param {string|number|Node|Node[]|NodeList|HTMLCollection} criteria - * Criteria to test against (see dom-is) * @returns {Element[]} Array of all (matching) children */ export default function domChildren(element, criteria) { if (!element || !element.children) return []; var children = Array.from(element.children); if (criteria) { children = children.filter(function (child) { return is(child, criteria); }); } return children; }