Skip to content

v3.2.0

Compare
Choose a tag to compare
@sammycage sammycage released this 16 Feb 12:25
· 8 commits to master since this release

πŸš€ 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! 🎨