Skip to content

Commit 30eee92

Browse files
gnarfrwaldron
authored andcommitted
Fix #14101: $().data() should be undefined, not null
1 parent cc19a6b commit 30eee92

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/data.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ jQuery.extend({
7575

7676
jQuery.fn.extend({
7777
data: function( key, value ) {
78-
var i, name,
79-
data = null,
78+
var i, name, data,
8079
elem = this[ 0 ],
8180
attrs = elem && elem.attributes;
8281

test/unit/data.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ test("jQuery.data(object/flash)", 25, function() {
170170
dataTests( flash );
171171
});
172172

173+
// attempting to access the data of an undefined jQuery element should be undefined
174+
test("jQuery().data() === undefined (#14101)", 2, function() {
175+
strictEqual(jQuery().data(), undefined);
176+
strictEqual(jQuery().data("key"), undefined);
177+
});
178+
173179
test(".data()", function() {
174180
expect(5);
175181

0 commit comments

Comments
 (0)