Make sure that undefined is returned for not found data- attributes, not null.
[jquery.git] / src / data.js
index f2cfc81..dda1683 100644 (file)
@@ -1,7 +1,7 @@
 (function( jQuery ) {
 
 var windowData = {},
-       rnum = /^-?[0-9.]$/;
+       rnum = /^-?\d+(?:\.\d+)$/;
 
 jQuery.extend({
        cache: {},
@@ -152,12 +152,15 @@ jQuery.fn.extend({
                                if ( data === undefined && this[0].nodeType === 1 ) {
                                        data = this[0].getAttribute( "data-" + key );
 
-                                       if ( data != null ) {
+                                       if ( typeof data === "string" ) {
                                                data = data === "true" ? true :
                                                        data === "false" ? false :
                                                        data === "null" ? null :
                                                        rnum.test( data ) ? parseFloat( data ) :
                                                        data;
+
+                                       } else {
+                                               data = undefined;
                                        }
                                }
                        }