cocktail-css-selector 0.1.4

css selector parsing/serializing and matching

Released 2014-07-20.

To install, run:

haxelib install cocktail-css-selector 0.1.4

See using Haxelib in Haxelib documentation for more information.

Current version0.1.4
StatisticsInstalled 16 times

Build Status


CSS selector matching, parsing and serializing. This lib is part of the larger Cocktail project.


haxelib install cocktail-css-selector


Selectors parsing

//parser class
import cocktail.selector.SelectorsParser;

//Selectors data structures
import cocktail.selector.SelectorData;

class Main {
  public static function main() {
    //parse one or multiple selectors and return them in an array of SelectorVO 
    //(see SelectorData implementation)
    var selectors = SelectorsParser.parse('div, p');

Selectors matching

//matcher class
import cocktail.selector.SelectorMatcher;

//Selectors data structures
import cocktail.selector.SelectorData;

//DOM lib
import cocktail.dom.*;

class Main {
  public static function main() {

    //create the DOM node to match
    var element = new Document().createElement('div');
    //takes a DOM node and a
    //selector and returns whether the element matches the 
    var isMatched = SelectorMatcher.match(element, 'div');

    //an optional object can be provided specifiying which pseudo-class
    //(hover, active, fullscreen... are currently active in the document).
    //It is only useful for interactive documents
    var matchedPseudoClasses = new MatchedPseudoClassesVO(/*bunch of flags*/);

    isMatched = SelectorMatcher.match(element, 'div', matchedPseudoClasses);

Run Tests