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

Commit 1169b54

Browse files
hsablonnieretbosch
authored andcommitted
fix(jqLite): ignore incompatible nodes on find()
When a jqLite collection contains text nodes, find() does not work :-( This fix ignores all nodes than can't do getElementsByTagName() It seems a little bit faster than testing nodeType : http://jsperf.com/nodetype-vs-duck-typing Closes #4120
1 parent 81b8185 commit 1169b54

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/jqLite.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,11 @@ forEach({
822822
},
823823

824824
find: function(element, selector) {
825-
return element.getElementsByTagName(selector);
825+
if (element.getElementsByTagName) {
826+
return element.getElementsByTagName(selector);
827+
} else {
828+
return [];
829+
}
826830
},
827831

828832
clone: jqLiteClone,

test/jqLiteSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,12 @@ describe('jqLite', function() {
13351335
expect(innerDiv.length).toEqual(1);
13361336
expect(innerDiv.html()).toEqual('text');
13371337
});
1338+
1339+
it('should find child by name and not care about text nodes', function() {
1340+
var divs = jqLite('<div><span>aa</span></div>text<div><span>bb</span></div>');
1341+
var innerSpan = divs.find('span');
1342+
expect(innerSpan.length).toEqual(2);
1343+
});
13381344
});
13391345

13401346

0 commit comments

Comments
 (0)