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

fix(jqLite): children() should only return elements #1739

Merged
merged 1 commit into from
Jan 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ forEach({
children: function(element) {
var children = [];
forEach(element.childNodes, function(element){
if (element.nodeName != '#text')
if (element.nodeType === 1)
children.push(element);
});
return children;
},

contents: function(element) {
return element.childNodes;
return element.childNodes || [];
},

append: function(element, node) {
Expand Down
13 changes: 7 additions & 6 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ describe('jqLite', function() {


describe('children', function() {
it('should select non-text children', function() {
var root = jqLite('<div>').html('before-<div></div>after-<span></span>');
it('should only select element nodes', function() {
var root = jqLite('<div><!-- some comment -->before-<div></div>after-<span></span>');
var div = root.find('div');
var span = root.find('span');
expect(root.children()).toJqEqual([div, span]);
Expand All @@ -934,11 +934,12 @@ describe('jqLite', function() {


describe('contents', function() {
it('should select all children nodes', function() {
var root = jqLite('<div>').html('before-<div></div>after-<span></span>');
it('should select all types child nodes', function() {
var root = jqLite('<div><!-- some comment -->before-<div></div>after-<span></span></div>');
var contents = root.contents();
expect(contents.length).toEqual(4);
expect(jqLite(contents[0]).text()).toEqual('before-');
expect(contents.length).toEqual(5);
expect(contents[0].data).toEqual(' some comment ');
expect(contents[1].data).toEqual('before-');
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/testabilityPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function dealoc(obj) {

function cleanup(element) {
element.unbind().removeData();
for ( var i = 0, children = element.children() || []; i < children.length; i++) {
for ( var i = 0, children = element.contents() || []; i < children.length; i++) {
cleanup(jqLite(children[i]));
}
}
Expand Down