Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(jqLite): make next() ignore non-element nodes
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
Keyamoon authored and IgorMinar committed Jan 8, 2013
1 parent b6b7c5a commit 76a6047
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion test/jqLiteSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

describe('jqLite', function() {
var scope, a, b, c;

Expand Down Expand Up @@ -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]);
});
});


Expand Down

0 comments on commit 76a6047

Please sign in to comment.