From 7651417f1eadaea07816929aff377aad55d1f012 Mon Sep 17 00:00:00 2001 From: patrik Date: Tue, 7 Jan 2020 13:43:14 +0100 Subject: [PATCH] support ',' in query selectors --- src/index.ts | 8 ++++++++ test/html.js | 1 + 2 files changed, 9 insertions(+) diff --git a/src/index.ts b/src/index.ts index 265cd6a..5d3da4c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -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[]; diff --git a/test/html.js b/test/html.js index adef4fc..741bd0d 100644 --- a/test/html.js +++ b/test/html.js @@ -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]); }); });