---
title: Scope
project: jComponent V19
version: 19.194
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v19/19-194/reference/scope/
updated: 2026-11-18T14:27:30.824Z
---

# Scope

> The properties and methods of a scope object.

A scope object represents a [`ui-plugin`](../ui-plugin/) element in the page. Paths used through the object are relative to the path of the scope. Get the object with `$(element).scope()`. [Scopes](../../guides/scopes/) explains the concept.

## API

### scope.path

Type: `property`

The absolute path of the scope.

Example: Reading path
```js
var scope = $('span').last().scope();
console.log(scope.path);  // users
```

### scope.id

Type: `property`

The unique generated identifier of the scope.

The same value is available as `ID`.

Example: Reading id
```js
var scope = $('span').last().scope();
console.log(scope.id === scope.ID);  // true
```

### scope.element

Type: `property`

The element of the scope as a jQuery object.

Example: Reading element
```js
var scope = $('span').last().scope();
console.log(scope.element.prop('tagName'));  // UI-PLUGIN
```

### scope.config

Type: `property`

The parsed configuration of the element.

Example: Reading config
```js
var scope = $('span').last().scope();
console.log(scope.config.limit);  // 10
```

### scope.parent

Type: `property`

The parent scope.

The property is `undefined` for a scope without a parent.

Example: Reading parent
```js
var scope = $('span').last().scope();
console.log(scope.parent.path);  // users
```

### scope.isolated

Type: `property`

Tells whether the path ignores the parent scope.

Example: Reading isolated
```js
var scope = $('span').last().scope();
console.log(scope.isolated);  // false
```

### scope.elements

Type: `property`

The elements of the parent scopes and of this scope.

The elements are DOM nodes, and the last one is the element of this scope.

Example: Reading elements
```js
var scope = $('span').last().scope();
console.log(scope.elements.length);  // 2
```

### scope.plugin

Type: `property`

The [Plugin](../plugin/) connected to the scope.

Example: Reading plugin
```js
var scope = $('span').last().scope();
console.log(scope.plugin.name);  // users
```

### scope.makepath(path)

Type: `method`

Resolves a path relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |

Returns: `String` The resolved path.

`?` is the path of the scope, `?1` is the path of the parent scope and `?2` is the path two levels up. When that level does not exist, the path of the scope is used.

Example: Using makepath()
```js
var scope = $('ui-plugin').scope();
console.log(scope.makepath('?.name'));  // users.name
```

### scope.get([path])

Type: `method`

Reads a path relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The relative path. |

Returns: `Object` The value.

Without an argument, the method returns the whole model.

Example: Using get()
```js
var scope = $('ui-plugin').scope();
console.log(scope.get('page'));  // 1
```

### scope.set(path, value, [timeout], [reset])

Type: `method`

Writes a value to a path relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The relative path. |
| `value` | `Object` | yes |  | The value. |
| `timeout` | `Number` | no |  | A value of `10` or more delays the change in milliseconds. A lower value is the type of the change. |
| `reset` | `Boolean` | no |  | `true` resets the state after a delayed change. |

Example: Using set()
```js
var scope = $('ui-plugin').scope();
scope.set('page', 2);
console.log(GET('users.page'));  // 2
```

### scope.push(path, value, [timeout], [reset])

Type: `method`

Adds an item to an array relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The relative path. |
| `value` | `Object` | yes |  | The item. |
| `timeout` | `Number` | no |  | A value of `10` or more delays the change in milliseconds. A lower value is the type of the change. |
| `reset` | `Boolean` | no |  | `true` resets the state after a delayed change. |

Example: Using push()
```js
var scope = $('ui-plugin').scope();
scope.push('items', 'A');
console.log(scope.get('items'));  // ["A"]
```

### scope.update([path], [timeout], [reset])

Type: `method`

Notifies the listeners of a path relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The relative path. |
| `timeout` | `Number` | no |  | A value of `10` or more delays the change in milliseconds. A lower value is the type of the change. |
| `reset` | `Boolean` | no |  | `true` resets the state. |

Example: Using update()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(value));  // 5
window.users.page = 5;
scope.update('page');
```

### scope.change([path])

Type: `method`

Marks components on a path as touched and modified.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The relative path. |

Example: Using change()
```js
var scope = $('ui-plugin').scope();
scope.change();
console.log(FIND('field').config.touched);  // true
```

### scope.reset([path])

Type: `method`

Clears the state of components on a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The relative path. |

The touched and modified state is cleared. The value does not change.

Example: Using reset()
```js
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.modify('Peter');
scope.reset();
console.log(com.config.touched, com.config.modified);  // false false
```

### scope.default([path], [timeout])

Type: `method`

Restores the default value of the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The relative path. |
| `timeout` | `Number` | no |  | The delay in milliseconds. |

The default value comes from the [`default`](../ui-plugin/#default) attribute of the element. A number as the first argument is a delay in milliseconds.

Example: Using default()
```js
var scope = $('ui-plugin').scope();
scope.set('page', 5);
scope.default();
console.log(scope.get('page'));  // 1
```

### scope.can()

Type: `method`

Tells whether the components in the scope can be saved.

Returns: `Boolean` The result.

The result is `true` when at least one component is touched and none is invalid. A scope without components returns `true`.

Example: Using can()
```js
var scope = $('ui-plugin').scope();
FIND('field').modify('Peter');
console.log(scope.can());  // true
```

### scope.errors()

Type: `method`

Returns the touched and invalid components of the scope.

Returns: `Array` The components.

Example: Using errors()
```js
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.validate = value => !!value;
com.bind('touched');
com.validate2();
console.log(scope.errors().length);  // 1
```

### scope.watch(path, callback, [init])

Type: `method`

Watches a path relative to the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The relative path. |
| `callback` | `Function` | yes |  | The function that receives the changes. |
| `init` | `Boolean` | no |  | `true` calls the callback immediately. |

Returns: `Scope` The scope.

The callback receives `path`, `value` and `type`, and `this` is the scope.

Example: Using watch()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(path, value));  // users.page 2
scope.set('page', 2);
```

### scope.unwatch(path)

Type: `method`

Removes the watchers of a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The relative path. |

Returns: `Scope` The scope.

The method removes all watchers that this scope has on the path.

Example: Using unwatch()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', () => console.log('called'));
scope.unwatch('page');
scope.set('page', 2);
console.log('end');  // end
```

### scope.apply()

Type: `method`

Makes the scope active.

Returns: `Scope` The scope.

Functions such as `SET()` then replace `?` with the path of this scope.

Example: Using apply()
```js
var scope = $('ui-plugin').scope();
scope.apply();
SET('?.page', 3);
console.log(GET('users.page'));  // 3
```

### scope.FIND(selector, [many], [callback], [timeout])

Type: `method`

Finds components inside the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The selector of the component. |
| `many` | `Boolean` | no |  | `true` returns an array. |
| `callback` | `Function` | no |  | Waits for the component and receives it. |
| `timeout` | `Number` | no |  | The longest wait in milliseconds. |

Returns: `Component|Array` The result.

The arguments are the same as in the jQuery `FIND()` extension.

Example: Using FIND()
```js
var scope = $('ui-plugin').scope();
console.log(scope.FIND('field').name);  // field
```

### scope.SETTER(selector, method, [...args])

Type: `method`

Calls a method of components inside the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The selector of the component. |
| `method` | `String` | yes |  | The name of the method. |
| `args` | `Object` | no |  | The arguments. |

Example: Using SETTER()
```js
var scope = $('ui-plugin').scope();
scope.SETTER('field/reconfigure', 'title:Orders');
console.log(FIND('field').config.title);  // Orders
```

### scope.RECONFIGURE(selector, value)

Type: `method`

Reconfigures components inside the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The selector of the component. |
| `value` | `String|Object` | yes |  | The configuration. |

Example: Using RECONFIGURE()
```js
var scope = $('ui-plugin').scope();
scope.RECONFIGURE('field', 'title:Orders');
console.log(FIND('field').config.title);  // Orders
```

### scope.find(selector)

Type: `method`

Finds nested elements.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String|Object` | yes |  | A selector or an object of selectors. |

Returns: `jQuery|Object` The result.

An object of selectors returns an object of jQuery results with the same keys.

Example: Using find()
```js
var scope = $('ui-plugin').scope();
console.log(scope.find('span').length);  // 1
```

### scope.closest(selector)

Type: `method`

Finds the closest matching parent of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The selector. |

Returns: `jQuery` The result.

Example: Using closest()
```js
var scope = $('ui-plugin').scope();
console.log(scope.closest('body').length);  // 1
```

### scope.append(value)

Type: `method`

Adds content to the end of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | yes |  | The content. |

Returns: `jQuery` The element.

An array is joined.

Example: Using append()
```js
var scope = $('ui-plugin').scope();
scope.append('<b>A</b>');
console.log(scope.find('b').text());  // A
```

### scope.event(name, [selector], callback)

Type: `method`

Attaches a jQuery event to the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `selector` | `String` | no |  | The delegated selector. |
| `callback` | `Function` | yes |  | The handler. |

Returns: `Scope` The scope.

The arguments are the same as in the jQuery `on()` method.

Example: Using event()
```js
var scope = $('ui-plugin').scope();
scope.event('click', 'span', () => console.log('clicked'));  // clicked
scope.find('span').click();
```

### scope.attr(name, [value])

Type: `method`

Reads or writes an attribute of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The attribute. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Scope` The value, or the scope when `value` is passed.

Example: Using attr()
```js
var scope = $('ui-plugin').scope();
scope.attr('title', 'Users');
console.log(scope.attr('title'));  // Users
```

### scope.attrd(name, [value])

Type: `method`

Reads or writes a `data-` attribute of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name without the `data-` prefix. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Scope` The value, or the scope when `value` is passed.

Example: Using attrd()
```js
var scope = $('ui-plugin').scope();
scope.attrd('id', '5');
console.log(scope.attr('data-id'));  // 5
```

### scope.attrd2(name)

Type: `method`

Reads a `data-` attribute from the element or its closest parent that has it.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name without the `data-` prefix. |

Returns: `String` The value.

Example: Using attrd2()
```js
var scope = $('ui-plugin').scope();
console.log(scope.attrd2('area'));  // main
```

### scope.css(name, [value])

Type: `method`

Reads or writes a CSS property of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The property. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Scope` The value, or the scope when `value` is passed.

Example: Using css()
```js
var scope = $('ui-plugin').scope();
scope.css('display', 'block');
console.log(scope.css('display'));  // block
```

### scope.autofocus([selector])

Type: `method`

Moves the focus to the first visible field in the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `input,select,textarea` | The fields. |

Returns: `Scope` The scope.

The method does nothing on mobile devices.

Example: Using autofocus()
```js
var scope = $('ui-plugin').scope();
scope.autofocus();
console.log(document.activeElement.tagName);  // INPUT
```

### scope.remove()

Type: `method`

Removes the scope, its element and its components.

Example: Using remove()
```js
var scope = $('ui-plugin').scope();
scope.remove();
console.log($('ui-plugin').length);  // 0
```
