diff --git a/src/jqLite.js b/src/jqLite.js index 8305f0c30f2c..d156ae6d3128 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -718,7 +718,16 @@ forEach({ }, next: function(element) { - return element.nextSibling; + if (element.nextElementSibling) { + return element.nextElementSibling; + } + + // IE8 doesn't have nextElementSibling + var elm = element.nextSibling; + while (elm != null && elm.nodeType !== 1) { + elm = elm.nextSibling; + } + return elm; }, find: function(element, selector) { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 01f9b9ae8138..b23e23eb1f05 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,4 +1,3 @@ - describe('jqLite', function() { var scope, a, b, c; @@ -1073,6 +1072,14 @@ describe('jqLite', function() { var i = element.find('i'); expect(b.next()).toJqEqual([i]); }); + + + it('should ignore non-element siblings', function() { + var element = jqLite('
bTextNodei
'); + var b = element.find('b'); + var i = element.find('i'); + expect(b.next()).toJqEqual([i]); + }); });