# html/select
Query a parsed document with a CSS selector list and get the matching
elements as Deft trees. `.class`, `#id`, attribute selectors,
combinators (`div > p`, `a b`), pseudo-classes (`:first-child`,
`:has()`, …) — the full selector language.
## Syntax
[html/select $src|$doc $selector]
## Parameters
- `$src` — HTML source text (string) or a `%HtmlDocument` handle from
`html/open`
- `$selector` — CSS selector list; comma separates alternatives
## Examples
set hits [html/select "<div><p class=x>1</p><p id=y>2</p><p>3</p></div>" "p.x, p#y"] [len $hits] # => 2 [nth [nth $hits 0]~children 0] # => "1" # Combinators set kids [html/select "<div><section><p>a</p></section><p>b</p></div>" "div > p"] [len $kids] # => 1 # Attribute selectors [html/select "<a href='x'>l</a><a>plain</a>" "a[href]"] # 1 hit # Repeat queries against one parse set d [html/open $page] each [html/select $d "a[href]"] {|a| echo $a~attrs~href } [html/close $d]
## Returns
A vector of element maps in the `html/parse` tree shape
(`%{ :tag :attrs :children }`), in document order. A node matching
several comma-list selectors appears once (matches are deduped). No
match is not an error — it returns an empty vector `@{}`.
An unparseable selector returns `%Err{ :message "html/select: invalid`
CSS selector" }`; so do parse failures when a string input is parsed.`
## See Also
`html/open`, `html/parse`, `html/text`, `re/match`