diff --git a/src/jqLite.js b/src/jqLite.js index 78fc1655fa27..6539aaabfbf8 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -342,7 +342,8 @@ forEach({ append: function(element, node) { forEach(new JQLite(node), function(child){ - element.appendChild(child); + if (element.nodeType === 1) + element.appendChild(child); }); }, @@ -371,8 +372,8 @@ forEach({ }, parent: function(element) { - // in IE it returns undefined, but we need differentiate it from functions which have no return - return element.parentNode || null; + var parent = element.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; }, next: function(element) { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 346017f1cf5a..3486fbbb872d 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,12 +1,13 @@ describe('jqLite', function(){ - var scope; - var a, b, c; + var scope, a, b, c; + beforeEach(function(){ a = jqLite('
deep deep
deep deep
foo
')).toBe(root); + expect(root.children().length).toBe(0); + }); }); + + describe('remove', function(){ it('should remove', function(){ var root = jqLite('abc
foo
'); + + fragment.appendChild(child[0]); + expect(child[0].parentNode).toBe(fragment); + expect(child.parent().length).toBe(0); + }); }); + + describe('next', function(){ it('should return next sibling', function(){ var element = jqLite('