This is a lower-level API. Lower-level APIs are not recommended for most projects, and may not be available on all plans. See our page on recommended deployment patterns for more information.
Event Annotations API

texthighlight:add

Triggered whenever a text highlight is added.

Examples

annotationsApp.on('texthighlight:add', function (textHighlightInfo) {
    var textHighlightModule = annotationsApp.module('texthighlight');
    var id = textHighlightInfo.id;
    var startElement = textHighlightModule.utils.deserializePath(
        textHighlightInfo.startContainerPath,
        textHighlightInfo.startOffset,
    );
    var endElement = textHighlightModule.utils.deserializePath(
        textHighlightInfo.endContainerPath,
        textHighlightInfo.endOffset,
    );

    console.log('The text selection with id ' + id + ' ranges between:', startElement, endElement);
});

Callback arguments

  • id string
    The unique id of the text highlight.
  • startContainerPath string
    A string representing the location of the DOM node that contains the start of the selection.
  • endContainerPath string
    A string representing the location of the DOM node that contains the end of the selection.
  • startOffset number
    The offset, in characters, of the start of the selection within the start container.
  • endOffset number
    The offset, in characters, of the end of the selection within the end container.
Was this article helpful?