Skip to content
Permalink
Browse files

core: Fixed #2605: .data() now accepts null as a value.

  • Loading branch information
scottgonzalez committed May 3, 2008
1 parent ad3c49d commit f8698395acbe428bd7c3dd6dd5700a0c660deeab
Showing with 11 additions and 6 deletions.
  1. +3 −3 src/core.js
  2. +8 −3 test/unit/core.js
@@ -465,13 +465,13 @@ jQuery.fn = jQuery.prototype = {
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";

if ( value == null ) {
if ( value === undefined ) {
var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);

if ( data == undefined && this.length )
if ( data === undefined && this.length )
data = jQuery.data( this[0], key );

return data == null && parts[1] ?
return data === undefined && parts[1] ?
this.data( parts[0] ) :
data;
} else
@@ -1412,16 +1412,21 @@ test("$.data", function() {
});

test(".data()", function() {
expect(16);
expect(18);
var div = $("#foo");
ok( div.data("test") == undefined, "Check for no data exists" );
div.data("test", "success");
ok( div.data("test") == "success", "Check for added data" );
div.data("test", "overwritten");
ok( div.data("test") == "overwritten", "Check for overwritten data" );

div.data("test", undefined);
ok( div.data("test") == "overwritten", "Check that data wasn't removed");
div.data("test", null);
ok( div.data("test") === null, "Check for null data");

div.data("test", "overwritten");
var hits = {test:0}, gets = {test:0};

div
.bind("setData",function(e,key,value){ hits[key] += value; })
.bind("setData.foo",function(e,key,value){ hits[key] += value; })

0 comments on commit f869839

Please sign in to comment.
You can’t perform that action at this time.