Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6340513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:50:59+00:00 2026-05-24T19:50:59+00:00

Just interested, which one’s faster? Couldn’t google it up. For example, $(‘li:first’) vs $(‘li’).first()

  • 0

Just interested, which one’s faster? Couldn’t google it up.

For example, $('li:first') vs $('li').first()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:51:01+00:00Added an answer on May 24, 2026 at 7:51 pm

    Update: apparently the parsing of the expression incurs a lot of overhead.
    In my quick benchmark .first() is a lot faster than using the selector.

    Expressions simply boil down to methods on the $.expr object like explained here

    The actual implementation of the :first vs the .first() differ a bit:

    Here the code for :first on $.expr.setFilters.first

    function ( elem, i ) {
      return i === 0;
    }
    

    while $.fn.first is simply a shorthand for .eq(0):

    function () {
      return this.eq( 0 );
    }
    

    without looking at the actual code I’d implement a first() like this if it wasn’t there:

    $.extend($.expr[':'],{
        first: function(a) {
            return $(a).first();
        }
    });
    

    This also means that :first is simply a filter on a list of elements, while .first() is a reduce operation that’s more efficient.

    Update2: Doh – Should have read the docs. Since jQuery tries to use native CSS selectors in modern browsers and :first is no selector from the CSS spec it will always perform a lot worse than a real selector that can take advantage of the browsers native CSS searching methods (whereas jQuery has to emulate that behavior in JS)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in texture streaming in DirectX but google seems unhelpful. Maybe I just
I just found an article on codeproject, which made me quite interested ... So
I'm just interested in people's opinions. When using nullable types in C# what is
I'm interested in implementing a Forth system, just so I can get some experience
I'm interested in finding out how to interface a .NET app (or even just
Just looking for the first step basic solution here that keeps the honest people
Just interested in knowing if there are any good (and short! :-) ) articles
I have a confusing problem in my code, in which one object gets initialized
Firstly, I realise that this is a very similar question to this one: Which
I'm often interested in cropping pdfs,* and one tool I use to do this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.