I have a container which contains multiple divs, of which i need to wrap two of them in another div, using jquery. Please suggest the possible way.
actual structure
<div class='parent'>
<div class='a'>abcd</div>
<div class='b'>abcd</div>
<div class='c'>abcd</div>
<div class='d'>abcd</div>
</div>
expected structure:
<div class='parent'>
<div class='a'>abcd</div>
<div class='child'>
<div class='b'>abcd</div>
<div class='c'>abcd</div>
</div>
<div class='d'>abcd</div>
</div>
use Jquery . wrapAll() - It wraps the html structure around all the matched elements.
You can use wrapAll()
function! It wraps all the elements that match the selector! :)
$('.b,.c').wrapAll('<div class="child"></div>');
JSFIDDLE DEMO
Use wrapAll method:
$('.b, .c').wrapAll('<div class="child" />');
inspect this demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With