Skip to content

Commit

Permalink
Merge pull request ashi009#12 from patrikpihlstrom/master
Browse files Browse the repository at this point in the history
support ',' in query selectors
  • Loading branch information
taoqf authored Jan 8, 2020
2 parents 8a481f5 + 7651417 commit 4b588b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ export class HTMLElement extends Node {
matcher = selector;
matcher.reset();
} else {
if (selector.includes(',')) {
const selectors = selector.split(',') as string[];
let result = [] as HTMLElement[];
selectors.forEach((s) => {
result = result.concat(this.querySelectorAll(s.trim()));
})
return result;
}
matcher = new Matcher(selector);
}
const res = [] as HTMLElement[];
Expand Down
1 change: 1 addition & 0 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ describe('HTML Parser', function () {
root.querySelectorAll('span.a.b').should.eql([root.firstChild.firstChild.firstChild]);
root.querySelectorAll('#id .b').should.eql([root.firstChild.firstChild.firstChild]);
root.querySelectorAll('#id span').should.eql(root.firstChild.firstChild.childNodes);
root.querySelectorAll('#id, #id .b').should.eql([root.firstChild, root.firstChild.firstChild.firstChild]);
});
});

Expand Down

0 comments on commit 4b588b6

Please sign in to comment.