How to push, pop, and wrap values in jQuery?

arrays, javascript, jquery

Solution

You mean like

jQuery(function ($) {
    //find all the target anchor elements
    var $as = $('a.plmore');

    //find the div elements
    $('.fcontainer').each(function (idx) {
        //wrap the div at index idx using the href value of anchor element at index idx
        $(this).wrap($('<a/>', {
            href: $as.eq(idx).attr('href')
        }))
    });
});

Demo: Fiddle

Problem

I've looked high and low and can't figure this one out! On a page, I have links that have a certain class (plmore). On the same page, I have divs that have a certain class (fcontainer) among others. The number of links with the class plmore will always equal the number of div using the fcontainer class. My question: I need to wrap the `div`s that have `fcontainer` class with the links found using plmore. PSEUDOCODE: GET ARRAY OF HREFS GET ARRAY OF DIV IDS WRAP DIVS WITH HREFS This is what I have so far: ``` <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> jQuery(document).ready(function($) { var hrefs = new Array(); $('a.plmore').each(function() { hrefs.push($(this).find('a').attr('href')); }); var features = new Array(); $('fcontainer').each(function() { features.push($(this).find('div').attr('id')); }); /* how does one pop from both arrays and wrap?? */ }); </script> ```

Original source