diff --git a/src/.jshintrc b/src/.jshintrc index 9f86b7648435..241e3feccb19 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -96,6 +96,7 @@ "skipDestroyOnNextJQueryCleanData": true, "NODE_TYPE_ELEMENT": false, + "NODE_TYPE_ATTRIBUTE": false, "NODE_TYPE_TEXT": false, "NODE_TYPE_COMMENT": false, "NODE_TYPE_COMMENT": false, diff --git a/src/Angular.js b/src/Angular.js index d2d5b6ace46d..e38580f79182 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -88,6 +88,7 @@ createMap: true, NODE_TYPE_ELEMENT: true, + NODE_TYPE_ATTRIBUTE: true, NODE_TYPE_TEXT: true, NODE_TYPE_COMMENT: true, NODE_TYPE_DOCUMENT: true, @@ -1739,6 +1740,7 @@ function createMap() { } var NODE_TYPE_ELEMENT = 1; +var NODE_TYPE_ATTRIBUTE = 2; var NODE_TYPE_TEXT = 3; var NODE_TYPE_COMMENT = 8; var NODE_TYPE_DOCUMENT = 9; diff --git a/src/jqLite.js b/src/jqLite.js index df1ab7312ea4..5f8338e29001 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -587,6 +587,10 @@ forEach({ }, attr: function(element, name, value) { + var nodeType = element.nodeType; + if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT) { + return; + } var lowercasedName = lowercase(name); if (BOOLEAN_ATTR[lowercasedName]) { if (isDefined(value)) { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 29848825a41a..a791641bcda0 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -612,6 +612,30 @@ describe('jqLite', function() { expect(elm.attr('readOnly')).toBeUndefined(); expect(elm.attr('disabled')).toBeUndefined(); }); + + it('should do nothing when setting or getting on attribute nodes', function() { + var attrNode = jqLite(document.createAttribute('myattr')); + expect(attrNode).toBeDefined(); + expect(attrNode[0].nodeType).toEqual(2); + expect(attrNode.attr('some-attribute','somevalue')).toEqual(attrNode); + expect(attrNode.attr('some-attribute')).toBeUndefined(); + }); + + it('should do nothing when setting or getting on text nodes', function() { + var textNode = jqLite(document.createTextNode('some text')); + expect(textNode).toBeDefined(); + expect(textNode[0].nodeType).toEqual(3); + expect(textNode.attr('some-attribute','somevalue')).toEqual(textNode); + expect(textNode.attr('some-attribute')).toBeUndefined(); + }); + + it('should do nothing when setting or getting on comment nodes', function() { + var comment = jqLite(document.createComment('some comment')); + expect(comment).toBeDefined(); + expect(comment[0].nodeType).toEqual(8); + expect(comment.attr('some-attribute','somevalue')).toEqual(comment); + expect(comment.attr('some-attribute')).toBeUndefined(); + }); });