Finding Things
The primary entry points into DOM are document.query() and document.queryAll(). Both take a CSS selector as the argument. The former returns a single matching element; the latter returns a list of all matching elements. Here are some simple examples:
dom/finding.dart | |
| document.query('h1'); // => First <h1> in the document |
| document.query('#people-list'); // => Element with id of 'people-list' |
| document.query('.active'); // => First element with 'active' class |
| document.queryAll('h2'); // => All <h2> elements |
The query and queryAll methods are actually methods of the Element class. Document, like every other class representing a bit of the DOM, subclasses Element. In practice, this means we can limit queries to ...
Get Dart 1 for Everyone now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.