Reputation: 276
I have a div containing an h3 and some divs. I want to essentially wrap all of the divs together in one container div, but Cheerio doesn't have a wrap or wrap-together function.
Right now I'm appending the container div, making it a sibling of the divs that need to be its children. But I'm at a loss as to how to move its siblings into this container. What I'd like to do is something like:
$("div.container").append($this.siblings("div"));
Essentially "append to this node, the div siblings of this node." But I can't figure out how to make the self reference.
Upvotes: 1
Views: 1137
Reputation: 7619
You can always create a new wrapper and move all the div children from the original container to the new one:
// Create a wrapper
var newDiv = $('<div>');
// Move all divs from #container to the wrapper
newDiv.append($('#container').find('div'));
Upvotes: 5