Multiple div wrap selector

I have two 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 immediately select both methods and use the .wrap()jQuery method ?

I know about multiple selector (,), but it doesn't work on my side.

I want the new div to be like this

  <div>
  <div class="bigfont-m capsletter"></div> 
  <div class="headfont6 text-overhide"></div>
  </div>
+4
source share
4 answers

You can use multiple selectors to select both elements, and then use .wrapAll () to wrap them in an element

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

Demo: Fiddle

+4
source

jQuery - select multiple classes

How to select an item with multiple classes?

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

jQuery wrapall()

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

You can use .add(), like all those already mentioned multiple selector. Then you can use.wrapAll()

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

Demo

0
source

Source: https://habr.com/ru/post/1548493/


All Articles