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().
This commit is contained in:
Keyamoon 2012-12-20 03:18:47 +03:30 committed by Igor Minar
parent de6cc287e5
commit c0995399d4
2 changed files with 18 additions and 2 deletions

View file

@ -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) {

View file

@ -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('<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]);
});
});