diff --git a/src/jqLite.js b/src/jqLite.js index 5e9d777a..a2dc02cd 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -266,7 +266,9 @@ forEach({ } else if (element.getAttribute) { // the extra argument "2" is to get the right thing for a.href in IE, see jQuery code // some elements (e.g. Document) don't have get attribute, so return undefined - return element.getAttribute(name, 2); + var ret = element.getAttribute(name, 2); + // normalize non-existing attributes to undefined (as jQuery) + return ret === null ? undefined : ret; } }, diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index fafe7f2a..2c05a7e5 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -162,6 +162,10 @@ describe('jqLite', function(){ expect(select.attr('multiple')).toEqual(true); }); + it('should return undefined for non-existing attributes', function() { + var elm = jqLite('