import matchHelper from "posthtml-match-helper";tree.match(matchHelper("div.class"), function (node) { // do stuff with matched node...});
Advanced usage
import matchHelper from "posthtml-match-helper";tree.match(matchHelper("input.my-control[type!='radio'][checked], input[value^='foo'][checked]"), function (node) { // do stuff with node that matched either of the selectors...});
Classnames with escaped characters
If you need to match nodes with classnames that use escaped characters, like those in Tailwind CSS utilities with arbitrary values, use the following syntax:
import matchHelper from "posthtml-match-helper";tree.match(matchHelper("input.\\[display:none\\]"), function (node) { // do stuff with node that matched either of the selectors...});
The helper function
Arguments
matcher (string) - A CSS selector that describes the node you want to match in PostHTML.