Skip to content
Permalink
Browse files

feat(jqLite): don't throw for elements with missing getAttribute

jQuery falls back to prop here but this feature is not very well tested
& documented so let's just skip it here.

Closes #15181
  • Loading branch information...
mgol committed Oct 5, 2016
1 parent d5b7803 commit 4e6c14dcae4a9a30b3610a288ef8d20db47c4417
Showing with 14 additions and 2 deletions.
  1. +3 −2 src/jqLite.js
  2. +11 −0 test/jqLiteSpec.js
@@ -640,7 +640,8 @@ forEach({
attr: function(element, name, value) {
var ret;
var nodeType = element.nodeType;
if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT) {
if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT ||
!element.getAttribute) {
return;
}

@@ -655,7 +656,7 @@ forEach({
} else {
element.setAttribute(name, isBooleanAttr ? lowercasedName : value);
}
} else if (element.getAttribute) {
} else {
// getter

ret = element.getAttribute(name);
@@ -751,6 +751,17 @@ describe('jqLite', function() {
elm.attr('multiple', '');
expect(elm[0].getAttribute('multiple')).toBe('multiple');
});

it('should not fail on elements without the getAttribute method', function() {
forEach([window, document], function(node) {
expect(function() {
var elem = jqLite(node);
elem.attr('foo');
elem.attr('bar', 'baz');
elem.attr('bar');
}).not.toThrow();
});
});
});


0 comments on commit 4e6c14d

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