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
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.
You can use wrapAll() function!
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).
The wrap() method wraps specified HTML element(s) around each selected element.
$('.one, .two, .three').wrapAll('<div class="wrap">');
or
$('.one, .two, .three').wrapAll( $('<div>').addClass('wrap') );
Reference: http://docs.jquery.com/Manipulation/wrapAll
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