JQuery wraps a lot of elements in a div

Hello, I would like to use jQuery to wrap element sets in a div

HTML:

<h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> <h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> <h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> 

Desired Result:

 <div class="box"> <h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> </div> <div class="box"> <h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> </div> <div class="box"> <h3>Title</h3> <ul> <li>Feature</li> <li>Feature</li> </ul> </div> 

My question is similar to the following, but I could not find the solution proposed by Russ Cam for work.

Wrap three repeating div groups into one using jQuery

Thanks in advance.

+5
source share
1 answer

Try the following:

 $(document).ready(function(){ $('h3').each(function(){ $(this).add( $(this).next() ).wrapAll('<div class="box"></div>'); }) }) 
+7
source

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


All Articles