This is a simple CSS selector written in pure JavaScript code. It aims to provide CSS selector functions to JSSoup. But it can do more as it has flexibility to support other dom packages as well (e.g. jsdom).
JSSoupSelector has implemented most basic selectors:
- Universal Selector
*
- Type Selector
div
- Class Selector
.class
- ID Selector
#id
- Attribute Selector
[title]
- Descendant Combinator
body div
- Child Combinator
body > div
- Next Sibling Combinator
body + div
- Subsequent Sibling Combinator
body ~ div
- Groups of Selectors
div.class, span#id, p[title]
$ npm install jssoup-selector
//react-native
import SoupSelector from 'jssoup';
// nodejs
var SoupSelector = require('jssoup-selector').default;
JSSoupSelector requires a dom adaptor class as input so that it can adapt dom element access functions to dom package specific functions. Now it only supports JSSoup adapter.
var selector = new SoupSelector(new JSSoupAdapter());
var soup = new JSSoup(data);
var elements = selector.select("*", soup)