Checking for length of ul and removing an li element
<p>I am trying to remove the last <code>&lt;li&gt;</code> element from a <code>&lt;ul&gt;</code> element only if it exceeds a particular length. For this, I am doing something like this:</p>

<pre><code>var selector = "#ulelement"
if($(selector).children().length &gt; threshold) {
   $(selector + " &gt;:last").remove();
}
</code></pre>

<p>I don't like the fact that I have to use the selector twice. Is there a shorter way to do this? Something like a "remove-if-length-greater-than-threshold" idea. I was thinking that maybe there is a way to do this using the live() function but I have no idea how.</p>
