jQuery if element does not contain element then create and append one?
<p>I have a <code>li</code> element that I am selecting like this:</p>

<pre><code>var parent_li = $(this).parent();
</code></pre>

<p>This element may or may not contain an <code>ul</code> element. I would like to add a child to the <code>ul</code> but if there is no <code>ul</code> element I would like to create and add it first.</p>

<p>I tried:</p>

<pre><code>if( !parent_li.children('ul') )
{
   //if the parent list doe not contain
   //an UL element, then add one
   parent_li.append($('&lt;ul&gt;&lt;/ul&gt;'));
}
</code></pre>

<p>However, I found out that parent_li.children('ul') always returns an object even if it does not have any child <code>ul</code> elements.</p>

<p>So what do I need to do?</p>
