-
Notifications
You must be signed in to change notification settings - Fork 44
Getting Started: 5. CSS Queries
Daniele Orlando edited this page Dec 17, 2020
·
4 revisions
XPath is very powerful but CSS Selectors are more concise sometimes.
Concise syntax
$eggs = $food('egg'); $fruits = $food('fruit[price="expensive"');Extended syntax
$eggs = $food->query('egg'); $fruits = $food->query('fruit[price="expensive"]');
Pro Tip:
Like for XPath,query()supports a variable number of CSS queries. In addition, XPaths and CSS Selectors can be mixed in the same query.$food('//title', 'chapters > chapter');
The supported CSS selectors are:
#id.classE[attr="val"]*:rootnamespace|EE EE > EE + EE ~ EE , E
Note:
Remember that CSS selectors are translated internally to XPath and this operation adds some overhead. If you need the best performances possible, go with XPath.