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 6841929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:01:49+00:00 2026-05-27T00:01:49+00:00

I need to speed up this jQuery line for select tag with possilbly several

  • 0

I need to speed up this jQuery line for select tag with possilbly several thousand option tags. Is there anything faster than the following jQuery line? Maybe javascript? I’m even looking for a replacement b/c code is slow and unresponsive if used in conjunction with a selecttagname change event.

var selectedsize = $("Select[name='selecttagname'] option:selected").size();


 <select multiple name='selecttagname'>
 <option selected="selected" value="1">Aladin</option>
 <option value="2">Atlantis</option>
.... ~5000 more of these</option></select>

Thanks.

  • 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-27T00:01:50+00:00Added an answer on May 27, 2026 at 12:01 am

    to start with, your selector is invalid so jQuery is manually parsing the selector AND the DOM tree to find your elements.

    this is a slight improvement over what you have:

    var count = $('select[name="selecttagname"]').find('option:selected').length
    

    notice how I also split the selector in 2, the first part will be accelerated by browsers that support querySelectorAll API and simplifies the second query which is still custom and will remain slow-ish (:selected is a jQuery extension). This is the best you can do with just jQuery.

    Now for possibly some extra speed you can manually query the DOM, not sure if this is gonna be faster, but you can skip the Sizzle parser for the ‘:selected’ part.

    try this:

    var count = $('select[name="selecttagname"] option').filter(function() {
        return this.selected;
    }).length;
    

    In theory, this last one is faster. Let us know what are your findings after testing it.

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

Sidebar

Related Questions

I need to speed up my coding, too much work, so I need be
I need to speed up a query. Is an index table what I'm looking
I need to get up to speed with C++ quite quickly (I've never used
I need a C++ JSON parser & writer. Speed and reliability are very critical,
Wondering if I can speed up the search. I need to build a functionality
I wanted to know is C# array has a constant access speed? I need
I'm an experienced client application developer (C++/C#), but need to come up to speed
Large datasets, millions of records, need special programming to maintain speed in DBGrids. I
Need to parse a Class declaration line in Java using regular expression e.g. String
My jQuery code (using ajax) request's data from a local php script (pgiproxy.php). 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.