mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-10 10:01:00 +00:00
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:
parent
de6cc287e5
commit
c0995399d4
2 changed files with 18 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue