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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:31:24+00:00 2026-06-09T11:31:24+00:00

I ran yesterday in a problem with a jquery-selector I assigned to a variable

  • 0

I ran yesterday in a problem with a jquery-selector I assigned to a variable and it’s driving me mad.

Here is a jsfiddle with testcase:

  • assign the .elem to my obj var
  • log both lengths to the console. Result => 4
  • Remove #3 from the DOM
  • log obj to the console => the removed #3 is still there and the length is still 4.
    I figured out that jquery query is snapshotted? to the variable and can’t?won’t? be updated
  • log .elem to the console.. yep Result => 3 and the #3 is gone
  • Now I update .elem with a new width of 300
  • logging obj & obj.width gives me 300.. So the snapshot has been updated ? What’s interesting is that 3 of the 4 divs have the new width, but the removed #3 doesn’t…

Another test: Adding a li element to the domtree and logging obj and .elem.
.elem does have the new li and obj doesn’t, because it’s still the old snapshot

http://jsfiddle.net/CBDUK/1/

Is there no way to update this obj with the new content?
I don’t want to make a new obj, because in my application there is a lot information saved in that object, I don’t want to destroy…

  • 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-09T11:31:26+00:00Added an answer on June 9, 2026 at 11:31 am

    Yeah, it’s a snapshot. Furthermore, removing an element from the page DOM tree isn’t magically going to vanish all references to the element.

    You can refresh it like so:

    var a = $(".elem");
    
    a = $(a.selector);
    

    Mini-plugin:

    $.fn.refresh = function() {
        return $(this.selector);
    };
    
    var a = $(".elem");
    
    a = a.refresh();
    

    This simple solution doesn’t work with complex traversals though. You are going to have to make a parser for the .selector property to refresh the snapshot for those.

    The format is like:

    $("body").find("div").next(".sibling").prevAll().siblings().selector
    //"body div.next(.sibling).prevAll().siblings()"
    

    In-place mini-plugin:

    $.fn.refresh = function() {
        var elems = $(this.selector);
        this.splice(0, this.length);
        this.push.apply( this, elems );
        return this;
    };
    
    var a = $(".elem");
    a.refresh() //No assignment necessary
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I ran into a g++ (3.4.6) compiler problem for code that I have
I was working on a method yesterday and ran into something strange, here is
Ran into problem with creating custom select dropdown plugin in jQuery. I'm at the
Yesterday I ran into a problem where the date of birth of a person
I ran into an interesting problem yesterday and while the fix was quite simple,
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
I ran into a problem that suggests I may be implementing a design pattern
I ran into an error yesterday and, while it's easy to get around, I
Yesterday, I decided to install the newest NCover version (3.4.2). However, when I ran
Ran into a small problem when change to OpenLayers 2.11 with showing the length

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.