3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getAncestorByClassName.js 710 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isString from './utils/types/isString'
import isElement from './isElement'
import parent from './parent'
import hasClass from './hasClass'
import getAncestorBy from './getAncestorBy'
/**
* @method getAncestorByClassName
* @since 1.10.0
* @param {HTMLElement} el
* @param {String} className
* @return {HTMLElement|null}
*/
const getAncestorByClassName = (el, className) => {
let $ancestor = null
let filter
if (!isElement(el) || !isString(className)) {
return $ancestor
}
$ancestor = parent(el)
if (!$ancestor) {
return null
}
filter = (el) => {
return hasClass(el, className)
}
return getAncestorBy($ancestor, filter)
}
export default getAncestorByClassName
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助