Skip to main content

$context

Create and access Accent Contexts through JavaScript.

Parameters#

ParameterTypeDescription
selectorHTMLElement stringThe ID of an existing Accent context or an HTML element reference of a new or existing context.
scopeObjectThe data that will be stored in the new Accent context.
idstringThe ID of the new Accent context.

Example#

Creating Accent Contexts#

Let's create an Accent context on the <body> element with the data { foo: 'bar' }. We will call this context.

Note: The id parameter is optional, even while creating Accent contexts.

Accent.$context(  document.body,  {    foo: "bar",  },  "bodyContext");

Accessing Accent Contexts#

To access existing Accent contexts, we will omit the scope and id parameters. Once accessed, the data of the context will be returned.

Accent.$context(document.body); // { foo: 'bar' }Accent.$context("bodyContext"); // { foo: 'bar' }