MacRabbit

SXSelector

JavaScriptAPI : SXSelector

SXSelector objects allow you to check if an SXZone or CEItem matches a selector. See Selectors for full documentation on selector syntax.

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