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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:26:55+00:00 2026-06-15T06:26:55+00:00

So, I have some JavaScript/jQuery that looks like this: var $foo = $(‘#bar’); $foo.hide();

  • 0

So, I have some JavaScript/jQuery that looks like this:

var $foo = $('#bar');
$foo.hide();

I’ve been operating under the assumption that jQuery operates on the given selector, and saves the resulting DOM element to the var $foo…which, as far as I can see is true.

However, does invoking $foo.hide() cause jQuery to re-seek the #bar element?

  • 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-15T06:26:56+00:00Added an answer on June 15, 2026 at 6:26 am

    No it doesn’t, reference is made when $(elem) is called. This is why var is used, to store reference to element. It is always best practice to store references to var so next time code is used, old reference is used, and there is no need for searching DOM again.

    //reference
    var a = $('#id');
    
    //use
    a.hide();
    
    //same reference, use again
    a.show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have some javascript code like this, var worker = new Worker(javascript/worker.js); worker.onmessage =
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
I have some code on a User Control that looks like this: <asp:PlaceHolder id=ph1
I have some code on my page that looks like this: <div class=img-center> <img
With some help from SO, I have a bit of javascript/jquery that cycles through
On my web pages I have source that looks like this: <div id=opt_3 >A)</div>
I have a plugin that looks like this: (function($) { $.fn.plugin_name = function(options) {
I have some ASP.Net code that defines a server-side checkbox like this: <asp:CheckBox ID=_chkWindAndHail
I have a dynamically-generated object that looks like this: colorArray = { AR: #8BBDE1,

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.