Skip to content
Advertisement

How to wrap the children/child of element with one tag using cheerio?

I have p tags inside div element.

I want to wrap the div children/child with div tag using cheerio library.

I try to use wrap: $('.parent').children().wrap('<div></div>'); But it wraps every element in my div.

Is it possible to wrap all the children with one tag div like this:

JavaScript

The code I try to do:

JavaScript

Advertisement

Answer

Use method wrapInner like that:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement