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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:38:02+00:00 2026-05-24T04:38:02+00:00

I often find myself building a list item row or something by grabbing a

  • 0

I often find myself building a list item row or something by grabbing a template, cloning it, setting it to a variable, and using find(‘.class’) to find elements under it, and then assigning them unique ids and otherwise working with them before appending the list item to whatever list I’m doing.

For example, if I have a list of items, all of which are set from a template, and include sub items, which are specified by class, I would do something like this (not tested, just a process example):

// Create my list item.
$ListItem = $('#list_item_template').clone();

// Set the id for the first field so I can work with it directly later.
$ListItem.find('.field_one).attr('id', 'field_one_'+ListItemID).val('field one value for this list item');

// Set the id for the second field so I can work with it directly later.
$ListItem.find('.field_two).attr('id', 'field_two_'+ListItemID).val('field two value for this list item');

// Add the item to the list
$ListItem.appendTo($List);

Now, I can access the first “field” of the Xth list item like $(‘#field_one_[ListItemID].

The problem is, even though I’m specifying the $ListItem, I know that when I use find(‘.field_one’) to find the field to add an id, it traverses every element in the template looking for that class. This isn’t much of a performance hit, but if it’s a long list, or a long template, it will add up.

Is there a more effective way to do this? Something like you would expect from a function called .findOnce()….?

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-24T04:38:03+00:00Added an answer on May 24, 2026 at 4:38 am

    It depends on how your DOM is setup. children() is faster than find(), for example, just like parent() is faster than parents().

    Example: $ListItem.children('.field_one')

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

Sidebar

Related Questions

I often find myself using Integers to represent values in different spaces. For example...
I often find myself writing a property that is evaluated lazily. Something like: if
I often find myself with a list of disconnected Linq2Sql objects or keys that
I often find myself wanting to just print (using the implicit toString() of each
I often find myself with fairly complex data that represents something that my objects
I often find myself wanting to collapse an n-dimensional matrix across one dimension using
I often find myself using lambdas as some sort of local functions to make
I often find myself remembering the name of a class that I want to
When programming in Stata I often find myself using the loop index in the
I often find myself adding either concatonated strings or using a string formatter in

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.