FragmentDirective

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The FragmentDirective interface is an object representing the text fragments highlighted in the current document.

It is accessed via the Document.fragmentDirective property.

Instance properties

None.

Instance methods

None.

Examples

Try running the following in a supporting browser's devtools, in a tab with one or more matched text fragments:

js

document.fragmentDirective;

You should get a FragmentDirective object instance returned with a structure similar to the following:

js

items: [
  {
    prefix: "",
    textStart: "Module Workers",
    textEnd: "",
    suffix: "support",
    type: "text",
  },
  {
    prefix: "feedback on",
    textStart: "usability",
    textEnd: "",
    suffix: "",
    type: "text",
  },
];

This functionality is mainly intended for feature detection at present, but in future, it could be expanded to include other information such as translation hints.

Specifications

Specification
URL Fragment Text Directives
# fragmentdirective

Browser compatibility

BCD tables only load in the browser

See also