3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getFirstChildBy.js 787 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isFunction from './utils/types/isFunction'
import isElement from './isElement'
import isMatched from './isMatched'
import getNextSiblingBy from './getNextSiblingBy'
/**
* 通过过滤函数获取指定 DOM 元素下的(全部) childNode 元素
* ========================================================================
* @method getFirstChildBy
* @since 1.10.0
* @param {HTMLElement} el
* @param {ChildNode} el.firstChild
* @param filter
* @return {HTMLElement|null}
*/
const getFirstChildBy = (el, filter) => {
let child = null
if (!isElement(el) || !isFunction(filter)) {
return child
}
if (isMatched(el.firstChild, filter)) {
child = el.firstChild
}
return child || getNextSiblingBy(el.firstChild, filter)
}
export default getFirstChildBy
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助