Question: I have a carousel slideshow where I want to select all images with their links. The problem is that there are linked images and just plain ones without links.

HTML:

```
 <ul class="slides">
        <li><a href="example.com">
            <img src="exampleimg1.jpg" /></a></li>
        <li>
            <img src="exampleimg2.jpg" /></li>
        <li><a href="example3.com">
            <img src="exampleimg3.jpg" /></a></li>
    </ul>

```

If I try `$('.slides li a')` I only get the ones with Links, but I need both. 
If I try `$('.slides li a, .slides li img')` I get all Images with links and without links, but the images with link appear twice(in this case 5, I need 3). I only want every image once.

EDIT1: ok. I forgot to mention a little detail. 

The <"li"> elements sometimes contain divs or h1(content comes from a CMS). Therefore the solutions mentioned above don't work.
I dont want the divs and h1 etc. included in the slideshow, only images and if present: images with links.

Sorry for not being clear the first time.

Updated example:

```
<ul class="slides">
<li>
  <div class="abc">
    <h1>some heading</h1>
      <a href="example.com">
        <img src="exampleimg1.jpg" />
      </a>
  </div>
</li>
<li>
  <div class="abcwrap">
    <img src="exampleimg2.jpg" />
  </div>
</li>
<li>
  <a href="example3.com">
     <img src="exampleimg3.jpg" />
  </a>
</li>
</ul>

```

Edit2: SOLVED IT!

If anybody is curious: 
selector:
$('.slides li img').parent()

Answer: 
Use [Child Selector (“parent > child”)](http://api.jquery.com/child-selector/) instead of [Descendant Selector (“ancestor descendant”)](https://api.jquery.com/descendant-selector/), if you want outer img.

```
$('.slides li a, .slides li > img')

```
Use ">" to select immediate child. 

```
$('.slides > li > a, .slides > li > img')

```

See <http://jsfiddle.net/a7XAw/1/>