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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:51:43+00:00 2026-06-13T10:51:43+00:00

I usually create variables for frequently reused DOM elements like this: var $dom_element =

  • 0

I usually create variables for frequently reused DOM elements like this:

var $dom_element = $('#dom_element);

where this is my setup:

<div id="dom_element">
  <div class="child_element">
  <div class="child_element">
</div>

what I’m wondering is if I can mix this variable with a subselector to get child elements. I guess it would be something like this:

var $child_element = $($dom_element + ' .child_element);

And if so, is there any speed benefit to doing this versus just saying:

$('.child_element);

considering the fact that both of these elements might be deeply nested in a large site?

  • 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-06-13T10:51:44+00:00Added an answer on June 13, 2026 at 10:51 am

    With

    var $dom_element = $('#dom_element);
    

    I would use the following to get the child elements

    var $child_element = $dom_element.find(".child_element");//I prefer this one, it is easier to read.
    

    or

    var $child_element = $(".child_element", $dom_element);
    

    From my research/reading, it appears that setting an element to a variable is best if you are going to reference it many times. That way jQuery does not have to search the DOM many times.

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

Sidebar

Related Questions

When I'm building a class library I usually create a file Enums.cs to hold
i just create reading file feature. In general, what kind PHP class that usually
It seems dead simple, as to create an NSURLConnection I usually do this: NSURL
Usually I put JavaScript like this : <head> <title>Title goes here</title> <script> some JavaScript
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table
Say I have a class like this: @interface MyAwesomeClass : NSObject { @private NSString
I usually create a pixel format using wglChoosePixelFormatARB() with these arguments (among others): WGL_DOUBLE_BUFFER_ARB
I usually create a gridview based on data so it will have the rows
So I usually create a feature branch in git, work on it, then merge
I am having two issues: I usually create separate view for the login to

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.