diff --git a/src/data.js b/src/data.js index 63920bb9e..8b285d266 100644 --- a/src/data.js +++ b/src/data.js @@ -75,8 +75,7 @@ jQuery.extend({ jQuery.fn.extend({ data: function( key, value ) { - var i, name, - data = null, + var i, name, data, elem = this[ 0 ], attrs = elem && elem.attributes; diff --git a/test/unit/data.js b/test/unit/data.js index bf5629644..086067cdc 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -170,6 +170,12 @@ test("jQuery.data(object/flash)", 25, function() { dataTests( flash ); }); +// attempting to access the data of an undefined jQuery element should be undefined +test("jQuery().data() === undefined (#14101)", 2, function() { + strictEqual(jQuery().data(), undefined); + strictEqual(jQuery().data("key"), undefined); +}); + test(".data()", function() { expect(5);