diff options
| author | Keyamoon | 2012-12-20 03:18:47 +0330 |
|---|---|---|
| committer | Igor Minar | 2013-01-08 14:54:15 -0800 |
| commit | 76a6047af690781b8238ba7924279470ba76d081 (patch) | |
| tree | 1fc16cac57f8fac4ce9f6b84a7dacd0f76d30544 | |
| parent | b6b7c5a1d66073937709158da8c2d688cb45c9f6 (diff) | |
| download | angular.js-76a6047af690781b8238ba7924279470ba76d081.tar.bz2 | |
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().
| -rw-r--r-- | src/jqLite.js | 11 | ||||
| -rw-r--r-- | test/jqLiteSpec.js | 9 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/jqLite.js b/src/jqLite.js index 8305f0c3..d156ae6d 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 01f9b9ae..b23e23eb 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('<div><b>b</b>TextNode<!-- comment node --><i>i</i></div>'); + var b = element.find('b'); + var i = element.find('i'); + expect(b.next()).toJqEqual([i]); + }); }); |
