query(selector)

This function of the context object (see context) returns a result set, containing the HTML elements in all sections of the Print context that match the supplied CSS selector.
The new result set is of the type QueryResults, just like the results object which is also the result of a (hidden) query (see results), but it is read-only.

This function can only be called in a Post Pagination Script (see Post Pagination Scripts). It is indispensable in a script that creates a table of contents, as described in the following topic: Creating a Table Of Contents.

selector

A String containing a CSS selector. See https://www.w3schools.com/cssref/css_selectors.asp for CSS selectors and combinations of CSS selectors.

Example

This script returns all level 1 headings in all sections of the Print context.

var headings = merge.context.query("h1");