Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 10da625

Browse files
vojtajinaIgorMinar
authored andcommitted
fix:jqLite: Normalize non-existing attributes to undefined as jQuery
jqLite was returning null, but jQuery returns undefined
1 parent 9ee9ca1 commit 10da625

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/jqLite.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ forEach({
266266
} else if (element.getAttribute) {
267267
// the extra argument "2" is to get the right thing for a.href in IE, see jQuery code
268268
// some elements (e.g. Document) don't have get attribute, so return undefined
269-
return element.getAttribute(name, 2);
269+
var ret = element.getAttribute(name, 2);
270+
// normalize non-existing attributes to undefined (as jQuery)
271+
return ret === null ? undefined : ret;
270272
}
271273
},
272274

test/jqLiteSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ describe('jqLite', function(){
162162
expect(select.attr('multiple')).toEqual(true);
163163
});
164164

165+
it('should return undefined for non-existing attributes', function() {
166+
var elm = jqLite('<div class="any">a</div>');
167+
expect(elm.attr('non-existing')).toBeUndefined();
168+
});
165169
});
166170

167171

0 commit comments

Comments
 (0)