Skip to main content

Bug Tracker

Side navigation

#14101 closed bug (fixed)

Opened July 03, 2013 06:17PM UTC

Closed November 06, 2013 03:27PM UTC

Last modified January 16, 2014 09:52PM UTC

Version 1.10 .data() differs from 1.8 when getting data from non-existent object

Reported by: Alex Robbin <> Owned by: gnarf
Priority: high Milestone: 1.11/2.1
Component: data Version: 1.10.1
Keywords: Cc: gnarf
Blocked by: Blocking:

This is a re-posting of ticket #13785, as it is still a problem in jQuery 1.10 but I am not able to re-open that ticket. I have reposted the information with new jsFiddles below.

In jQuery 1.8.3 (jsFiddle here), when you have attempted to retrieve a data key from an element that doesn't actually exist on the page, the result from data() was "undefined". In jQuery 1.9.1 (jsFiddle here) and jQuery 1.10.1 (jsFiddle here), that result is now "null". I have just had the jsFiddles do an alert showing what the value is when attempting to call .data() on an element that doesn't exist.

When gathering some data values from an element in order to pass them along to a subsequent POST request, I am building a basic javascript object that I then pass to $.post(). In jQuery 1.8.3, if the element did not exist (which can definitely happen on occasion), the params looked like this:

{id: undefined, type: undefined}

When $.post() then took that object to parameterize it, no parameters are actually POSTed to the /test/endpoint. However, in jQuery 1.9.1, the params look like this:

{id: null, type: null}

Because null values aren't stripped out/ignored when doing a $.post() like undefined values are, two empty values are POSTed, which our back-end system is not expecting.

Interestingly, when you call .data() on an element that does exist but has no value for the supplied data key, the return value is undefined in jQuery 1.9.1. It is only when the element doesn't actually exist on the page that the value has changed between 1.8.3 and 1.9.1.

Again, I am not sure if this is done purposefully or not, but in the gist that I have linked to, you'll see that the implementation does actually change (and jQuery migrate does not mitigate it).

I hope I have been clear in explaining the change, and any insight you guys can give me would be greatly appreciated. Thanks!

Attachments (0)
Change History (9)

Changed July 03, 2013 06:46PM UTC by timmywil comment:1

component: unfileddata
milestone: None1.10.3/2.0.4
priority: undecidedhigh
status: newopen

Changed July 03, 2013 08:17PM UTC by rwaldron comment:2

owner: → rwaldron
status: openassigned

Changed July 03, 2013 08:23PM UTC by rwaldron comment:3

cc: → gnarf
owner: rwaldron
status: assignedopen

Actually, I'm going to bail out for this one and ping Corey

Changed September 16, 2013 01:21AM UTC by dmethvin comment:4

milestone: 1.10.3/

Bulk update for new milestone

Changed November 05, 2013 02:59PM UTC by rwaldron comment:5

owner: → gnarf
status: openassigned

Changed November 05, 2013 08:05PM UTC by gnarf comment:6

Changed November 06, 2013 03:27PM UTC by rwaldron comment:7

Changed November 06, 2013 04:10PM UTC by gnarf comment:8

Changed January 16, 2014 09:52PM UTC by dmethvin comment:9

summary: JQUERY 1.10'S .DATA() RESULT DIFFERS FROM 1.8 WHEN ATTEMPTING TO GET DATA FROM A NON-EXISTENT OBJECT.Version 1.10 .data() differs from 1.8 when getting data from non-existent object