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/)
I think this can be done using the attribute contains selector.
<http://api.jquery.com/attribute-contains-selector/>

Example:
<http://jsfiddle.net/6aktY/1/>

```
$("ul.list1 li img").each( function() {
    var url = $( this ).attr( 'src' );
    var search_results = $( 'ul.list2 li img[src*="' + url + '"]' );

    if( search_results.size() === 0 )
    {
        $( 'ul.list2' ).append( '<li><a href="#"><img src="' + url + '" /></a></li>' );
    }
});

```