This seems incredibly simple but I cannot understand why it doesn't work.
$('.some-containers').each(function () {
var $ul = $(this).find('ul');
var $items = $ul.find('li');
console.log($items.length); //5
if ($items.length > 2) {
var $last = $items.last().detach();
console.log($items.length); //still 5
}
}
My question is why, after removing or detaching the last item, is the last item still there?