Ai
1 Star 0 Fork 12

NextZero/dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unwrap.js 927 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isString from './utils/types/isString'
import isCollection from './isCollection'
import replace from './replace'
import isMatched from './isMatched'
/**
* 从 DOM 中移除匹配元素集的父元素,将匹配的元素保留在它们的位置
* ========================================================================
* @method unwrap
* @since 1.1.0
* @param {HTMLCollection|NodeList} collection
* @param {String} selector
*/
const unwrap = (collection, selector) => {
let $collection = []
if (!isCollection(collection) || !isString(selector)) {
return false
}
$collection = [...collection]
if ($collection.length < 1) {
return false
}
$collection.forEach(($node, i) => {
const $parent = $node.parentNode
/* istanbul ignore else */
if (isMatched($parent, selector)) {
replace($node, $parent)
}
})
}
export default unwrap
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/nextzero/dom.js.git
git@gitee.com:nextzero/dom.js.git
nextzero
dom.js
dom.js
main

搜索帮助