Skip to content

Commit

Permalink
support ',' in query selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
patrik committed Jan 7, 2020
1 parent 8a481f5 commit 7651417
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 7651417

Please sign in to comment.