Espresso

SXSelector

SXSelector objects allow you to check if an SXZone or CEItem matches a selector. Full documentation on selectors.

SXSelector(selector)

The SXSelector constructor accepts a selector as a single string argument:

var selector = new SXSelector('html tag, xml tag');

Methods

matches(node)

Returns true or false; whether the SXZone or CEItem passed in as the node matches this selector.

// Find SXZone at start of first selection
var selection = context.selectedRanges[0];
var zone = context.syntaxTree.zoneAtCharacterIndex(selection.location);
// Check if that zone is an HTML or XML tag
var selector = new SXSelector('html tag, xml tag');
if (selector.matches(zone)) {
	// Do something with the HTML tag
}