How to count all elements of a certain type in a jQuery object?
<p>Say I have a jQuery object of uncertain contents (from <code>something</code> that could be a dynamic selector or a string of HTML):</p>

<pre><code>var $o = $(something);
</code></pre>

<p>Now, for example how do I count how many <code>&lt;div&gt;</code> objects are contained <em>in the jQuery object itself</em> (i.e. no descendants of the contained elements)? I could do</p>

<pre><code>var l = $o.filter( function () { return $(this).is("div"); } ).length;
</code></pre>

<p>Other ideas?</p>
