v3.2.0
π New Feature: Document::querySelectorAll()
querySelectorAll()
is a powerful way to select multiple elements from a Document
using CSS selectors. Unlike getElementById()
, which only fetches a single element by its ID, querySelectorAll()
allows you to retrieve multiple elements that match the given selector(s).
It works exactly like the JavaScript querySelectorAll()
method in the DOM:
π MDN Reference
π Example Usage
Consider an SVG with multiple <circle>
elements:
<svg width="200" height="200">
<circle cx="50" cy="50" r="40" fill="red" />
<circle cx="150" cy="50" r="40" fill="blue" />
</svg>
βοΈ This selects all <circle>
elements and stores them in an ElementList
.
ElementList circles = document->querySelectorAll("circle");
Now, let's update all circles to green:
for (Element& circle : circles) {
circle.setAttribute("fill", "green");
}
β All circles turn green! π¨