jquery - selecting multiple elements with same class and then filtering by id
<p>.post is the class of elements which also have an unique id such as "c1", "c14" etc (representing the post count on the page).</p>

<p>The code below will be part of an ajax call which regularly pulls new posts while also checking the current amount of posts on the page. Should the amount exceed 5, the older posts are removed.</p>

<p>Posts to be removed will have the smallest ids. How could I select them? Or would there be a better method of selecting the older messages (which are in bottom, similar to youtube).</p>

<pre><code>var postcount = $(".post").length;

while(postcount &gt; 5){
$("#c" + divtoremove).fadeOut(1000);
}

&lt;div class="post" id="c6"&gt;Post 6&lt;/div&gt;
&lt;div class="post" id="c5"&gt;Post 5&lt;/div&gt;
&lt;div class="post" id="c4"&gt;Post 4&lt;/div&gt;
&lt;div class="post" id="c3"&gt;Post 3&lt;/div&gt;
&lt;div class="post" id="c2"&gt;Post 2&lt;/div&gt;
&lt;div class="post" id="c1"&gt;Post 1&lt;/div&gt;
</code></pre>

<p>In this example "c1" should be removed. I can't keep count of the elements, I need to recalculate it on each call since it got messed up when I tried to keep a count.</p>
