Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap 3 divs in one with jQuery

Tags:

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

like image 698
Dom Avatar asked Oct 06 '09 15:10

Dom


People also ask

How do I wrap a div inside a div?

If you've faced the situation when you need to wrap words in a <div>, you can use the white-space property with the "pre-wrap" value to preserve whitespace by the browser and wrap the text when necessary and on line breaks. Also, you'll need the word-wrap property.

How do you wrap two divs?

You can use wrapAll() function!

What is wrap in jQuery?

jQuery wrap() method is used to wrap specified HTML elements around each selected element. The wrap () function can accept any string or object that could be passed through the $() factory function. Syntax: $(selector).

What is the purpose of wrap method?

The wrap() method wraps specified HTML element(s) around each selected element.


1 Answers

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

or

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

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

like image 176
meder omuraliev Avatar answered Nov 03 '22 00:11

meder omuraliev