I would like to wrap all elements of a container except the first one:
<div class="anyclass">
<p>First</p>
<p>Second</p>
<ul><li>List</li></ul>
<p>Third</p>
</div>
This should become
<div class="anyclass">
<p>First</p>
<div class="wrapit">
<p>Second</p>
<ul><li>List</li></ul>
<p>Third</p>
</div>
</div>
This doesn't work.
$( ".anyclass p, anyclass ul" ).wrapAll( "<div class='wrapit' />");
Also it wraps ALL elements. But I need the exception of the first element.
Update: And how can I do it the other way round? That means, just unwrapping the .wrapit-container.
$('.anyclass').children('p,ul').not(':first-child').wrapAll('<div class="wrapit" />');
should do the trick
unwrapping can be done by the .unwrap()
function:
$('.anyclass').children('.wrapit').children().unwrap();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments