Question: I have 2 unordered lists both containing images but list2 will have the same images as list1 but with additions.

I would like to check list2 image sources with list1 image sources and if there are image sources which missing from list1 I would like to add them.

Here is an example of the lists

```
 <ul class="list1">
     <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
     <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
     <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
     <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
  </ul>

<ul class="list2">
    <li><a href="#"><img src="http://lorempixel.com/400/400/"/></a></li>
    <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
    <li><a href="#"><img src="http://lorempixel.com/200/200/"/></a></li>
    <li><a href="#"><img src="http://lorempixel.com/400/200/"/></a></li>
</ul>

```

Here is a fiddle of what I think should be done but I'm not so sure now.
<http://jsfiddle.net/pNtHQ/4/>

something like check sources for both lists and the missing ones from list1 get added.

Answer: 
There are a few different ways to approach this, here's mine:

```
$("ul.list2 li img").each(function () {
    var imgSrc = $(this).attr("src")
    var matched = $("ul.list1 li img[src='" + imgSrc + "']");
    if (!matched.length) {
        $("ul.list1").append("<li><a href='#'><img src='" + imgSrc + "'/></a></li>")
    }
});

```

See it in action [here](http://jsfiddle.net/pNtHQ/5/)
You can try this -

```
$('.list1 img').each(function(){
  var src = $(this).attr('src');
  if($('.list2').find('img[src="'+src+'"]').length === 0){
   $('.list2').append($(this).closest('li').clone());
  }
})

```

Demo `-->` <http://jsfiddle.net/pNtHQ/7/>