Count number of dynamically created elements
<p>I've used the below code to dynamically wrap characters with a span.</p>

<pre><code>    $("span.count").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(\w)/g, "&lt;span&gt;$&amp;&lt;/span&gt;"));
    }
});
</code></pre>

<p>I am trying to (once complete) count the number of wrapped elements so I can attach a class based on the quantity to their container. I've tried various methods (thinking my problem is that is is trying to count dynamically created content) but none seem to work. Below is what I have so far:</p>

<pre><code>    var n = $("span.count").live().children().length;
if (n &lt; 3) {
    $(".counter").addClass("four");
}
</code></pre>

<p>Any help would be greatly appreciated.</p>
