Please see this image:

Can someone explain the difference?
Edit
Let me indicate what puzzles me. Notice that:
$row.is('tr.items:last') === false$row[0].id === $('tr.items:last')[0].id
The two statements seem to contradict each other. The first tells us that $row is not the last of tr.items. But the second one tells that $row is exactly $('tr.items:last'), i.e. the last of tr.items.
No such thing occurs with the :last-of-type selector.
What is going on here?
jQuery does a different filter mechanism for
.iswhen it comes to set filters like:last. The point is that it normally uses.filteron the current set and checks whether there are any elements left after filtering.This works for cases such as:
But for
:lastthis fails, because such a filter is relative to the set. Consider a document with two elements:This is in contrast with what you may expect. So, jQuery instead searches for
a:lastin the current context and checks whethera:firstis apparent in that set.The problem in your case is that
$(ev.target)(inhandleKeyDown) makes the context to be that input element and not the document (which is the usual case). Notr.itemscan be found in that context and you getfalse. This is arguably a bug in jQuery.Anyway, what you can do is checking against a set instead. It is faster to use the corresponding functions, anyway: