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>
anbuteau
  • 45
  • 5

4 Answers4

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

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
0

jQuery - Selecting Multiple Classes

How can I select an element with multiple classes?

$('bigfont-m.capsletter, headfont6.text-overhide') is your selector
Community
  • 1
  • 1
MikeB
  • 2,382
  • 1
  • 13
  • 24
0

Use jQuery wrapall() method

Example

$('div.bigfont-m.capsletter,div.headfont6.text-overhide').wrapAll('<div></div>');
Community
  • 1
  • 1
Jaykumar Patel
  • 25,525
  • 12
  • 68
  • 75
0

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

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

DEMO

Satpal
  • 129,808
  • 12
  • 152
  • 166