In jQuery, which is faster to execute: $("li").last() or $("li:last-child") ?
In jQuery, which is faster to execute: $(li).last() or $(li:last-child) ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Though both are different in what they do but here is result I got from jsperf:
http://jsperf.com/li-last-vs-li-last-child
$(“li”).last()
And
$(“li:last-child”)
So
$("li").last()is faster.FYI
$("li").last()selects the absolute last element whereas$("li:last-child")selects every last element in a series of grouped elements. That also makes it obvious that$("li").last()should be faster which it is.