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

  • Home
  • SEARCH
  • 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 7495327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:02:10+00:00 2026-05-29T18:02:10+00:00

Is there an alternative to building selector strings in jquery? In particular, I am

  • 0

Is there an alternative to building selector strings in jquery?

In particular, I am trying to extract information from the labels of several form elements, so I need to create queries like $('[for=#id]'). It seems inelegant (and probably inefficient) to have to create the query strings on every pass of every iteration over the form elements.

The only similar question I can find is jQuery (anti-)pattern: building selectors with string manipulation which doesn’t have any useful answers.

  • 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-29T18:02:12+00:00Added an answer on May 29, 2026 at 6:02 pm

    At-least limit the search to the form in which you are looking. Searching by attributes is in-efficient because you have to iterate over every element in the root set of elements. so instead of searching every element in the DOM, limit your search:

    var forID = $('#my-form').find('[for=#id]');
    

    You can make this a bit faster by searching for labels inside the form, then filtering down to just what you want:

    var $allLabels = $('#my-form').find('label');
    
    //then you can find a specific element by searching in the $allLabels object.
    $allLabels.filter('[for="#id"]');
    

    If your labels don’t change dynamically then you should cache their selection outside of your loop; always cache values that do not change within the loop, outside of the loop.

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

Sidebar

Related Questions

I'm building an alternative Home application (a replacement of the standard launcher). There's something
is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks
Is there any alternative image manipulation library for .net? I would prefer something that
Is there any alternative for WPF (windows presentation foundation) in python? http://msdn.microsoft.com/en-us/library/aa970268.aspx#Programming_with_WPF
Is there an alternative to history.go(-1) for FireFox and Safari. Any Help would be
Is there an alternative ActionScript 3 lightweight framework out there similar to Flex, but
Is there any alternative to Axis2? Or the way to make it work (different
Is there an alternative version of std::find_if that returns an iterator over all found
Is there an alternative in OpenSSL to SSL_set_connect_state()/SSL_set_accept_state() for X.509 certificate based authentication? The
Is there any alternative to this: Organizations.Include(Assets).Where(o => o.Id == id).Single() I would like

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.