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
  • 384,651
  • 66
  • 527
  • 531
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,402
  • 1
  • 15
  • 24
0

Use jQuery wrapall() method

Example

$('div.bigfont-m.capsletter,div.headfont6.text-overhide').wrapAll('<div></div>');
Community
  • 1
  • 1
Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76
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
  • 132,252
  • 13
  • 159
  • 168