Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab two randomly generated divs and wrap within custom div

I am trying to get the two randomly generated div ID's shown below and wrap them within my custom div that I can control. Was searching around on jQuery API for solution but still no ideas.

Here's a preview of example: 2 Randomly Generated ID's + Custom Class

Okay so as you can see, there are two <div id="random_string"></div> and one custom <div class="wrap_awm"></div>

Since I can't target the two ID's from above I have no clues how to tell jQuery, get the two div's from above wrap_awm and put them inside of the ".wrap_awm". Simple as that?

like image 635
dvlden Avatar asked Jan 13 '23 08:01

dvlden


1 Answers

What you're looking for is called .prevAll():

var $wrap = $('.wrap_awm');
$wrap.prevAll(':lt(2)').appendTo($wrap);

It's combined with the :lt() selector to only use the first two elements.

like image 124
Ja͢ck Avatar answered Feb 04 '23 11:02

Ja͢ck