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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:27:43+00:00 2026-06-10T18:27:43+00:00

I know jQuery doesn’t cache collections of element, f.ex calling: $(‘.myclass’).html(‘hello’); $(‘.myclass’).html(‘bye’); Will make

  • 0

I know jQuery doesn’t cache collections of element, f.ex calling:

$('.myclass').html('hello');
$('.myclass').html('bye');

Will make jQuery climb the DOM twice.

But how about cached DOM nodes?

var elems = document.querySelectorAll('.myclass');

$(elems).html('hello');
$(elems).html('bye');

Will jQuery cache those internally, or will they be equally slow as the first example?

To clarify: will jQuery keep a reference to elems and cache $(elems) internally so it won’t have to apply the same $() wrapper every time?

Something like:

cache = {}
constructor = function(collection)
    if collection in cache
        return cache[collection]
    else construct(collection)
  • 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-10T18:27:45+00:00Added an answer on June 10, 2026 at 6:27 pm

    Assuming I’ve understood your question correctly, then no, jQuery won’t keep a reference to the selected nodes beyond the statement that uses them:

    $('.myclass').html('hello'); //Select all .myclass elements, then change their HTML
    $('.myclass').html('bye'); //Select all .myclass elements, then change their HTML again
    

    If you maintain a reference to those selected nodes separately, it will be faster:

    var elems = document.querySelectorAll('.myclass'); //Select all .myclass elements
    $(elems).html('hello'); //Change their HTML (no need to select them)
    $(elems).html('bye'); //Change their HTML (no need to select them)
    

    The difference won’t be massive (unless your DOM is very complicated) but there will be a difference:

    enter image description here


    Update

    will jQuery keep a reference to elems and cache $(elems) internally so
    it won’t have to apply the same $() wrapper every time?

    No, it won’t. As stated above, the reference to the matched set of elements will not be maintained beyond the statement to which it applies. You can improve the performance of your code by keeping a reference to jQuery objects that are used throughout, rather than selecting them again each time, or even wrapping a stored set of native DOM nodes in a jQuery object each time.

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

Sidebar

Related Questions

I am using Jquery.js and i want to know does the browser cache the
I know jQuery does most when it comes to cross-browser issues. I just wanted
what does this code performs? if(object.jquery){ .... } I don't know what jQuery attribute
Does anyone know of a jQuery plugin that has 'helpers' or extensions like those
Does anyone know the d3 equivalent to jQuery attribute selector: $('[attribute=name]') I want to
Does anyone know if theres a jquery autocomplete library that works similar to the
Does anybody know how/when/why/who/where of if the JQuery intellisense files live for JQuery 1.4.2.
Does anyone know where I may find a really simple easy jQuery and PHP
Does anyone know what's going to be in the next version of jquery (1.3.3
Does anyone know why .hide(normal) does not seem to be working in jQuery 1.4.2?

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.