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

Commit

Permalink
fix:jqLite: Normalize non-existing attributes to undefined as jQuery
Browse files Browse the repository at this point in the history
jqLite was returning null, but jQuery returns undefined
  • Loading branch information
vojtajina authored and IgorMinar committed Jul 13, 2011
1 parent 9ee9ca1 commit 10da625
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},

Expand Down
4 changes: 4 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div class="any">a</div>');
expect(elm.attr('non-existing')).toBeUndefined();
});
});


Expand Down

0 comments on commit 10da625

Please sign in to comment.