The .unwrap() function, removes the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
Optional
A selector to check the parent element against. If an element's parent does not match the selector, the element won't be unwrapped.
The instance itself, for chaining.
const $ = cheerio.load( '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>',);$('#test p').unwrap();//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div> Copy
const $ = cheerio.load( '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>',);$('#test p').unwrap();//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div>
const $ = cheerio.load( '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>',);$('#test p').unwrap('b');//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div> Copy
const $ = cheerio.load( '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>',);$('#test p').unwrap('b');//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div>
https://api.jquery.com/unwrap/
The .unwrap() function, removes the parents of the set of matched elements from the DOM, leaving the matched elements in their place.