3 Star 54 Fork 14

Yaohaixiao / dom.js

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
unwrap.js 927 Bytes
Copy Edit Raw Blame History
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
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

Search