aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHubert SABLONNIÈRE2013-10-25 21:52:49 +0200
committerTobias Bosch2013-12-03 09:45:06 -0800
commit1169b5445691e1495354d235a3badf05240e3904 (patch)
treeb901dd059e234cfb38bcc9d655e9c6c37446cf9f
parent81b81856ee43d2876927c4e1f774affa87e99707 (diff)
downloadangular.js-1169b5445691e1495354d235a3badf05240e3904.tar.bz2
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
-rw-r--r--src/jqLite.js6
-rw-r--r--test/jqLiteSpec.js6
2 files changed, 11 insertions, 1 deletions
diff --git a/src/jqLite.js b/src/jqLite.js
index 218efe24..e7531fb3 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -822,7 +822,11 @@ forEach({
},
find: function(element, selector) {
- return element.getElementsByTagName(selector);
+ if (element.getElementsByTagName) {
+ return element.getElementsByTagName(selector);
+ } else {
+ return [];
+ }
},
clone: jqLiteClone,
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 02a17df8..09be1c1c 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -1335,6 +1335,12 @@ describe('jqLite', function() {
expect(innerDiv.length).toEqual(1);
expect(innerDiv.html()).toEqual('text');
});
+
+ it('should find child by name and not care about text nodes', function() {
+ var divs = jqLite('<div><span>aa</span></div>text<div><span>bb</span></div>');
+ var innerSpan = divs.find('span');
+ expect(innerSpan.length).toEqual(2);
+ });
});