I need help with my jQuery script. I have a page that refreshes every 10 seconds, and new divs from the feed are added to.
My script counts the div and removes the last div when there are more than 20 divs. This works great if the feed simply adds 1 div at a time. But the feed can also add multiple divs at the same time. When this happens, the counter can exceed a maximum of 20 divs. The problem is that my script just removes 1 div, and not all divs that exceed 20.
This is my code:
var $auto_refresh = setInterval(function () { var $articleCount = $('div').length; if ($articleCount > 20) { $('div:last-child').remove(); } $autoUpdate(); }, 10000);
I need to remove all additional divs, so there are always 20 divs. Hope someone can help me with this.
source share