3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getChildrenBy.js 693 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2024-05-10 14:25 . chore: 更新新添方法代码逻辑
import getFirstChildBy from './getFirstChildBy'
import getNextSiblingBy from './getNextSiblingBy'
/**
* 通过过滤函数获取指定 DOM 元素下的 childNode 元素
* ========================================================================
* @method getChildrenBy
* @since 1.10.0
* @param {HTMLElement} el
* @param {Function} filter
* @return {HTMLElement[]|*[]}
*/
const getChildrenBy = (el, filter) => {
const child = getFirstChildBy(el, filter)
const children = child ? [child] : []
let $next = getNextSiblingBy(child, filter)
while ($next) {
children.push($next)
$next = getNextSiblingBy(child, filter)
}
return children
}
export default getChildrenBy
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助