I was wondering if there is any difference between .filter(':last')
and .last()
?
For me it looks like they're doing the same, but I'm new to jQuery. If there is no difference in the result, which one is recommended or is it just a matter of personal preference?
last
works by saying "give me the last element from the selection". It takes just two function calls and four lines of code to do so. It can't be done in a quicker way.
filter(':last')
, however, is much more complex. It is a much more flexible system, allowing multiple elements to be returned if that's what you want, or multiple conditions, or a mixture of both. It is much less efficient, because it has to work out what you want. For instance, parsing ':last'
takes a little time, whereas with the last
function it's a simple property lookup.
last
is by far the more efficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With