Q:

If span exists add class to link

I have a list of links that I retrieve by AJAX. I parse the links and append them to a div. However sometimes there is a 'span' just after the 'a' that I need to take into consideration.
The code looks like this:
<ul>
   <li><a href="/link1" class="list-link">Link1 </a></li>
   <li><a href="/link1" class="list-link">Link1 </a><span class="sometimes-here"></span></li>
   <li><a href="/link1" class="list-link">Link1 </a></li>
   ...
</ul>

So what I want to do is to locate when a 'li' consist of a span and then apply that class ('sometimes-here') as an additional class to the 'a'.
I should elaborate what I need a bit as you only answered how to filter out all the 'li' that doesn't consist of the span. I want the end result to look like this.
<a href="/link1" class="list-link">Link1 </a>
<a href="/link1" class="list-link sometimes-here">Link1 </a>
<a href="/link1" class="list-link">Link1 </a>

A:

try this
$('li:has(span)').find('a').addClass('yourClass');

