Dom
Dom

Reputation: 3126

Wrap 3 divs in one with jQuery

I need to wrap 3 divs into one using jQuery.

<div class="one"></div><div class="two"></div><div class="three"></div>

into this

<div class="wrap"><div class="one"></div><div class="two"></div><div class="three"></div></div>

How can I do that please?

Many Thanks for your help in advance

Upvotes: 16

Views: 16774

Answers (1)

meder omuraliev
meder omuraliev

Reputation: 186562

$('.one, .two, .three').wrapAll('<div class="wrap">');

or

$('.one, .two, .three').wrapAll( $('<div>').addClass('wrap') );

Reference: http://docs.jquery.com/Manipulation/wrapAll

Upvotes: 29

Related Questions