|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "html" for Document
|
|
|
|
var doc = Document.parse("<div id='root'><section><p>A</p><p>B</p></section><article><p>C</p></article></div>")
|
|
|
|
var root = doc.getElementById("root")
|
|
var all = root.querySelectorAll("p")
|
|
System.print(all.count) // expect: 3
|
|
|
|
var section = doc.querySelector("section")
|
|
var sectionPs = section.querySelectorAll("p")
|
|
System.print(sectionPs.count) // expect: 2
|
|
System.print(sectionPs[0].textContent) // expect: A
|
|
System.print(sectionPs[1].textContent) // expect: B
|
|
|
|
var article = doc.querySelector("article")
|
|
var articlePs = article.querySelectorAll("p")
|
|
System.print(articlePs.count) // expect: 1
|
|
System.print(articlePs[0].textContent) // expect: C
|
|
|
|
var none = section.querySelectorAll("article")
|
|
System.print(none.count) // expect: 0
|
|
|