4

I have 2 elements that I want to wrap with a new div.

  <div class="bigfont-m capsletter"></div> 
  <div class="headfont6 text-overhide"></div>

Is it possible to select both at once and use the .wrap() JQuery method ?

I know about the multiple selector (,) but not working on my side.

What I want is the new div to be like that

  <div>
  <div class="bigfont-m capsletter"></div> 
  <div class="headfont6 text-overhide"></div>
  </div>

4 Answers 4

5

You can use multiple selector to select both the elements and then use .wrapAll() to wrap them with an element

$('.bigfont-m.capsletter, .headfont6.text-overhide').wrapAll('<div class="wrapper"/>')

Demo: Fiddle

1
  • @upvoters: You are all simply showing partiality.. :D Commented Jul 15, 2014 at 13:35
0

jQuery - Selecting Multiple Classes

How can I select an element with multiple classes?

$('bigfont-m.capsletter, headfont6.text-overhide') is your selector
0

Use jQuery wrapall() method

Example

$('div.bigfont-m.capsletter,div.headfont6.text-overhide').wrapAll('<div></div>');
0

You can use .add(), As everyone already mentioned multiple selector, Then you can use .wrapAll()

$('.capsletter').add('.headfont6').wrapAll('<div class="wrapper" />')

DEMO

Not the answer you're looking for? Browse other questions tagged or ask your own question.