From c0995399d4226504069f1b9e378260d0553c1fcc Mon Sep 17 00:00:00 2001 From: Keyamoon Date: Thu, 20 Dec 2012 03:18:47 +0330 Subject: fix(jqLite): make next() ignore non-element nodes next() is supposed to return the next sibling *element* so it should ignore text nodes. To achieve this, nextElementSibling() should be used instead of nextSibling(). --- src/jqLite.js | 11 ++++++++++- test/jqLiteSpec.js | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index 7b6e5da9..2afcef54 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -717,7 +717,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 76a2c5a8..a5e7b34e 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,4 +1,3 @@ - describe('jqLite', function() { var scope, a, b, c; @@ -1068,6 +1067,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]); + }); }); -- cgit v1.2.3