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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:03:04+00:00 2026-05-11T22:03:04+00:00

Fire up your firebug console and try this out. Compare this: $(‘body’).data(‘x’,1); $(thisx).remove(); console.log($(‘body’).data(‘x’));

  • 0

Fire up your firebug console and try this out.

Compare this:

$('body').data('x',1);
$(thisx).remove();
console.log($('body').data('x'));

to this:

$('body').data('x',1);
$(this.x).remove();
console.log($('body').data('x'));

Notice the difference? If thisx is undefined, it will immediatly throw a reference error. If x is an undefined property of this, jQuery will return the document as it’s result set instead. Next jQuery will attempt to remove your document (which it can’t), but before doing that it will remove all data attached to any child element of the document. Thus, wiping out your data store.

Note: this can be any element reference or object. You only need to have jQuery attempt to access an undefined property.

(Talk about a pain. It fails silently, and I’m trying to figure out why my data is suddenly missing. I track it down to a special case where an element reference was undefined in a specific situation.)

So on to my questions:

1) Before I submit a bug report, am I analyzing this correctly? Also if someone happens to know that this is a known issue, let me know. I couldn’t find it in the bug tracker, but the interface isn’t that great (or maybe I have this wrong).

2) Why is there ultimately any difference? I’m guessing thisx is evaluated immediately which causes the exception while this.x is a reference that is passed and evaluated in the called function, right? (where I think the line selector = selector || document; is the culprit.

3) Suggestions for how to handle this? I guess I should be checking that any/every element reference or property of an object (e.g. stored selector strings) is defined before I pass it to jQuery when removing something.

  • 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-11T22:03:04+00:00Added an answer on May 11, 2026 at 10:03 pm

    Why is there ultimately any difference?

    Both thisx and this.x are evaluated when the function is called. The first one refers to an undefined variable name and this throws a reference error. The second one accesses an undefined property of an object, which results in the value undefined. This is just how javascript behaves in these cases.

    Now when JQuery is called in the second case, the call $(this.x) evaluates to $(undefined) which is the same as if you just would have called $(). Since it looks to JQuery as if no argument was provided, it uses a default instead, and in this case the default is document. Then it proceeds trying to delete document, since it was effectively called as $().remove(), in which case this would be expected.

    Suggestions for how to handle this?

    The difference with the ReferenceError is a fundamental Javascript difference, not much that can be done about that. JQuerys behavior is unfortunate and a consequence of setting defaults by arg = arg||default. One could user arguments.length instead to get the real number of call parameters, but a change like this would surely result in lot’s of broken code that relied on the default being used when undefined or 0 is passed, so it’s unlikely to happen.

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

Sidebar

Ask A Question

Stats

  • Questions 271k
  • Answers 271k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The assembler just produces object files. It's up to the… May 13, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer Sounds like the Office (PowerPoint) COM components are not installed… May 13, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer display: none images will be downloaded and cached on the… May 13, 2026 at 1:49 pm

Related Questions

Fire up your firebug console and try this out. Compare this: $('body').data('x',1); $(thisx).remove(); console.log($('body').data('x'));
I have been trying to use a simple jQuery operation to dynamically match and
Alright SQL Server Gurus, fire up your analyzers. I have a list of titles
Basically, some GoDaddy DNS help text has me scratching my head. Godaddy's DNS service
I'm trying to develop some SharePoint workflows for the company I work for, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.