Length of jQuery collection object doesn't change after calling detach() on an element

Viewed 503

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?

1 Answers
Related