If span exists add class to link
<p>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.</p>

<p>The code looks like this:</p>

<pre><code>&lt;ul&gt;
   &lt;li&gt;&lt;a href="/link1" class="list-link"&gt;Link1 &lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="/link1" class="list-link"&gt;Link1 &lt;/a&gt;&lt;span class="sometimes-here"&gt;&lt;/span&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="/link1" class="list-link"&gt;Link1 &lt;/a&gt;&lt;/li&gt;
   ...
&lt;/ul&gt;
</code></pre>

<p>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'.</p>

<p>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.</p>

<pre><code>&lt;a href="/link1" class="list-link"&gt;Link1 &lt;/a&gt;
&lt;a href="/link1" class="list-link sometimes-here"&gt;Link1 &lt;/a&gt;
&lt;a href="/link1" class="list-link"&gt;Link1 &lt;/a&gt;
</code></pre>
