3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getPreviousSibling.js 769 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isElement from './isElement'
import isText from './isText'
/**
* 获取 DOM 元素的前一个邻居元素节点
* ========================================================================
* @method getPreviousSibling
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/previousElementSibling
* @param {HTMLElement|Text} el
* @param {HTMLElement} el.previousElementSibling
* @param {ChildNode} el.previousSibling
* @param {Boolean} [isElementSibling]
* @return {HTMLElement|null}
*/
const getPreviousSibling = (el, isElementSibling = true) => {
if (!isText(el) && !isElement(el)) {
return null
}
return isElementSibling ? el.previousElementSibling : el.previousSibling
}
export default getPreviousSibling
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891