Can someone explain the difference between .last() and :last ? I can’t seem to find a definitive explanation.
Why Exactly does this $('td.cellsOfSpecificClass:last', '.table tr') return the last td in each tr instead of the last td in the whole table?
The
.last()is a function which returns the last element of the given (existing) collection of elements. The:lastis a selector which is to be used in$('...')which immediately returns the last element instead of a whole collection. Which one to use depends on what you’ve as far and what you need.Update: to clarify the last phrase a bit more:
If you already have a collection of elements in a variable at the moment you need the last element, then use
.last(). If you don’t already have it and you just need only the last element, then use:last. If you actually need both in the remnant of the code, then grab all elements and use.last().