Q:

jQuery get each background image URL of each element and wrap it in a href

So i am trying to get the background-image url of each div that has the class "client" in it. From there I want put that URL into an a href and wrap around another element so i can make it pop in a light box.
I've gotten this far but it only seems to grab the first url and then applies it to all of the elements. 
// Make client rotator pop-up and get image url

jQuery(document).ready(function(){
jQuery('.client').each(function(index, el) {
   var bgurl =  $('.bg-cover').css('background-image');

    if(bgurl != 'none') {
        bgurl = bgurl.replace('url("','').replace('")','');
        jQuery('.client .flex_cell_inner').wrapInner('<a href="'+ bgurl +'" rel="lightbox"></a>');
    };
});
});

here is the URL to the site. go to our clients section in the homepage near the bottom: http://staging.idgadvertising.com/locationconnection/

A:

Try this. If you're trying to get the background image of each item, you should use $(this) which references the current item in the loop (in this case, each .client div as you loop over them). The way you have it now is referencing a collection of every .client div on the page.
$(document).ready(function(){
  $('.bg-cover').each(function(index, el) {
    var bgurl = $(this).css('background-image');

    if (bgurl != 'none') {
      bgurl = bgurl.replace('url("','').replace('")','');
      $($('.client .flex_cell_inner')[index]).wrapInner('<a href="'+ bgurl +'" rel="lightbox"></a>');
    };
  });
});

