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

feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find #3598

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ forEach({
},

find: function(element, selector) {
return element.getElementsByTagName(selector);
return (element.querySelectorAll || element.getElementsByTagName).call(element, selector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can drop the getElementsByTagName fallback since all browsers that we care about already support this.

},

clone: JQLiteClone,
Expand Down
7 changes: 7 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,13 @@ describe('jqLite', function() {
expect(innerDiv.length).toEqual(1);
expect(innerDiv.html()).toEqual('text');
});

it('should find child by an advanced selector', function() {
var root = jqLite('<div><div><span>a</span><span>b</span><span>c</span></div></div>');
var innerDiv = root.find('div > span:nth-child(2)');
expect(innerDiv.length).toEqual(1);
expect(innerDiv.html()).toEqual('b');
});
});


Expand Down