---
title: jQuery extensions
project: jComponent V19
version: 19.194
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v19/19-194/reference/jquery/
updated: 2026-11-18T13:58:29.465Z
---

# jQuery extensions

> Methods that jComponent adds to jQuery for working with classes, attributes, SVG, components and scopes.

jComponent includes jQuery and adds these methods to `$.fn`, so they work on every jQuery object. The [Component](../component/) page describes the objects returned by the component methods, and [Using components](../../guides/using-components/) explains how components are declared.

## API

### el.aclass(name, [delay])

Type: `method`

Adds one or more classes, immediately or after a delay.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The class names, separated by spaces. |
| `delay` | `Number` | no |  | The delay in milliseconds. |

Returns: `jQuery` The same element.

Delayed calls share one timer per element, so a new delayed `aclass()`, `rclass()` or `rclass2()` call cancels the one still waiting.

Example: Add a class
```html
<div id="box"></div>

<script>
var el = $('#box');
el.aclass('active');
el.hclass('active'); // true

el.aclass('later', 50);
el.hclass('later'); // false

setTimeout(function() {
	console.log(el.hclass('later'));
}, 100);
</script>
```

### el.asvg(tag)

Type: `method`

Appends an SVG element to the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | A tag name, or SVG markup. |

Returns: `jQuery` The new element, when `tag` is a tag name.

A tag name creates one element in the SVG namespace and returns it. A text with markup appends all of its elements; use a tag name when you need the new element afterwards.

Example: Append SVG elements
```html
<svg id="chart"></svg>

<script>
var svg = $('#chart');

svg.asvg('circle').attr('r', 5);
svg.asvg('<rect width="3"/><line/>');

svg.children().length; // 3
svg.children()[0].namespaceURI; // "http://www.w3.org/2000/svg"
</script>
```

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

Type: `method`

Reads or writes a `data-` attribute.

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

Returns: `String or jQuery` The value when reading, the same element when writing.

Example: Data attributes
```html
<div id="box" data-id="7"></div>

<script>
var el = $('#box');

el.attrd('id'); // "7"
el.attrd('name', 'Ann');
el.attr('data-name'); // "Ann"
</script>
```

### el.attrd2(name)

Type: `method`

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

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

Returns: `String` The value, or `undefined`.

Example: Inherit a value
```html
<div data-id="7"><span id="child"></span></div>

<script>
$('#child').attrd2('id'); // "7"
$('#child').attrd2('missing'); // undefined
</script>
```

### el.autofocus([selector])

Type: `method`

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

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

Returns: `jQuery` The same element.

When no field can take the focus, the method retries every 200 milliseconds, up to 15 times. It does nothing on mobile devices.

Example: Focus a form
```html
<div id="form">
	<input id="hidden" style="display:none">
	<input id="name">
	<textarea id="note"></textarea>
</div>

<script>
$('#form').autofocus();
document.activeElement.id; // "name"

$('#form').autofocus('textarea');
document.activeElement.id; // "note"
</script>
```

### el.binder()

Type: `method`

Returns the binder of the element or its nearest parent.

Returns: `Object` The binder, or `null`.

See [ui-bind](../ui-bind/).

Example: Read a binder
```html
<ui-bind path="user.name" config="show"><span id="label"></span></ui-bind>

<script>
setTimeout(function() {
	console.log($('#label').binder().path);
}, 500);
</script>
```

### el.CMD(name, [a], [b], [c], [d], [e])

Type: `method`

Runs a command in all components inside the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The command name. |
| `a` | `Object` | no |  | The first of up to five arguments for the command. |

Components register commands with `self.command()`. See [Component](../component/).

Example: Run a command
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', function(self) {
	self.make = function() {
		self.command('reset', function(value) {
			console.log(self.path, value);
		});
	};
});

ON('ready', function() {
	$('#panel').CMD('reset', 0);
});
</script>
```

### el.component()

Type: `method`

Returns the component of the element or its nearest parent.

Returns: `Component` The component, or `null`.

Example: Find the parent component
```html
<ui-component name="counter" path="data.a"><b id="inner"></b></ui-component>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	console.log($('#inner').component().path);
});
</script>
```

### el.components([fn])

Type: `method`

Lists or walks the ready components inside the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | no |  | Called for each component. |

Returns: `Array or jQuery` Without `fn`, an array of components, or `null` when there are none. With `fn`, the component elements.

With `fn`, the function is called with the component as `this` and the position of its element as the argument.

Example: Walk components
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	console.log($('#panel').components().length);
	$('#panel').components(function(index) {
		console.log(index, this.path);
	});
});
</script>
```

### el.EXEC(name, [args...])

Type: `method`

Calls a method on the components inside the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The method name, optionally with the prefix `^`. |
| `args` | `Object` | no |  | The arguments of the method. |

Returns: `jQuery` The same element.

With the prefix `^`, the method is called on the components in the parent elements. Components without the method are skipped.

Example: Call a method
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	$('#panel').EXEC('hello', 'Ann');
});
</script>
```

Example: Call a method on the parents
```html
<ui-component name="counter" path="data.a"><b id="inner"></b></ui-component>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	$('#inner').EXEC('^hello', 'Bob');
});
</script>
```

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

Type: `method`

Finds components inside the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The component selector. |
| `many` | `Boolean` | no |  | Use `true` to get all matching components. |
| `callback` | `Function` | no |  | Receives the result when it is available. |
| `timeout` | `Number` | no |  | The maximum waiting time in milliseconds. |

Returns: `Component, Array or jQuery` The first component, or an array with `many`. With `callback`, the same element.

The selector can be a component name, `name[path]`, `.path`, `#id` or `*`.

With `callback`, the method waits until a component exists and then calls `callback(component)`, with the component also as `this`. When `timeout` runs out first, the callback is not called. `many` can be left out when you pass a callback.

Example: Find components
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	var panel = $('#panel');
	console.log(panel.FIND('counter').path);
	console.log(panel.FIND('counter', true).length);
	console.log(panel.FIND('.data.b').path);
	console.log(panel.FIND('counter[data.b]').path);
});
</script>
```

Example: Wait for a component
```html
<div id="panel"></div>

<script>
$('#panel').FIND('late', function(component) {
	console.log('found', component.path);
}, 3000);

COMPONENT('late', function(self) {});
$('#panel').append('<ui-component name="late" path="data.late"></ui-component>');
COMPILE();
</script>
```

### el.hclass(name)

Type: `method`

Checks whether the element has a class.

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

Returns: `Boolean` `true` when the class is present.

Example: Check a class
```html
<div id="box" class="active"></div>

<script>
$('#box').hclass('active'); // true
$('#box').hclass('missing'); // false
</script>
```

### el.multiple(selectors)

Type: `method`

Runs several `find()` calls and returns the results under their names.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectors` | `Object` | yes |  | Names and selectors. |

Returns: `Object` jQuery objects under the same names.

Example: Find several elements
```html
<div id="form"><input id="name"><button>Save</button></div>

<script>
var ui = $('#form').multiple({ name: 'input', save: 'button' });

ui.name.attr('id'); // "name"
ui.save.text(); // "Save"
</script>
```

### el.plugin()

Type: `method`

Returns the plugin that contains the element.

Returns: `Plugin` The plugin, or `undefined`.

See [Plugin](../plugin/).

Example: Reach a plugin
```html
<ui-plugin path="orders"><div id="inner"></div></ui-plugin>

<script>
PLUGIN('orders', function(exports) {
	exports.total = function() {
		return 3;
	};
});

setTimeout(function() {
	console.log($('#inner').plugin().total());
}, 500);
</script>
```

### el.psvg(tag)

Type: `method`

Prepends an SVG element to the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | A tag name, or SVG markup. |

Returns: `jQuery` The new element, when `tag` is a tag name.

It works like [asvg()](#asvg), and the new content goes first.

Example: Prepend an SVG element
```html
<svg id="chart"><circle r="5"></circle></svg>

<script>
var svg = $('#chart');

svg.psvg('text').attr('x', 1);
svg.children()[0].nodeName; // "text"
</script>
```

### el.rattr(name)

Type: `method`

Removes an attribute.

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

Returns: `jQuery` The same element.

Example: Remove an attribute
```html
<div id="box" title="Hello"></div>

<script>
$('#box').rattr('title').attr('title'); // undefined
</script>
```

### el.rattrd(name, [name2], ...)

Type: `method`

Removes one or more `data-` attributes.

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

Returns: `jQuery` The same element.

Example: Remove data attributes
```html
<div id="box" data-a="1" data-b="2" data-c="3"></div>

<script>
var el = $('#box').rattrd('a', 'b');

el.attr('data-a'); // undefined
el.attr('data-b'); // undefined
el.attr('data-c'); // "3"
</script>
```

### el.rclass([name], [delay])

Type: `method`

Removes classes, immediately or after a delay.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | The class names, separated by spaces. |
| `delay` | `Number` | no |  | The delay in milliseconds. |

Returns: `jQuery` The same element.

Without a name, all classes are removed. Delayed calls share one timer per element, so a new delayed `aclass()`, `rclass()` or `rclass2()` call cancels the one still waiting.

Example: Remove classes
```html
<div id="box" class="a b c"></div>

<script>
var el = $('#box');

el.rclass('a').attr('class'); // "b c"
el.rclass().attr('class'); // ""
</script>
```

### el.rclass2(search, [delay])

Type: `method`

Removes the classes that contain a text or match a regular expression.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String or RegExp` | yes |  | The text to look for, or a regular expression. |
| `delay` | `Number` | no |  | The delay in milliseconds. |

Returns: `jQuery` The same element.

Delayed calls share one timer per element, so a new delayed `aclass()`, `rclass()` or `rclass2()` call cancels the one still waiting.

Example: Remove by pattern
```html
<div id="box" class="size-1 size-2 color-red ok"></div>

<script>
var el = $('#box');

el.rclass2('size-').attr('class'); // "color-red ok"
el.rclass2(/^color/).attr('class'); // "ok"
</script>
```

### el.RECONFIGURE(selector, value)

Type: `method`

Changes the configuration of components inside the element.

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

Returns: `jQuery` The same element.

The selector has the same forms as in [FIND()](#find).

Example: Reconfigure components
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', 'step:1', function(self) {});

ON('ready', function() {
	var panel = $('#panel');
	panel.RECONFIGURE('counter', 'step:5');
	console.log(panel.FIND('counter').config.step);
	panel.RECONFIGURE('counter', { step: 9 });
	console.log(panel.FIND('counter').config.step);
});
</script>
```

### el.scope()

Type: `method`

Returns the scope that contains the element.

Returns: `Scope` The scope. Outside a scope, the result is empty.

See [Scope](../scope/).

Example: Read the scope path
```html
<ui-plugin path="orders"><div id="inner"></div></ui-plugin>

<script>
PLUGIN('orders', function(exports) {});

setTimeout(function() {
	console.log($('#inner').scope().path);
}, 500);
</script>
```

### el.SETTER([wait], selector, method, [args...])

Type: `method`

Calls a method on the components inside the element that match a selector.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `wait` | `Boolean` | no |  | Use `true` to wait for the component. |
| `selector` | `String` | yes |  | The component selector. |
| `method` | `String` | yes |  | The method name. |
| `args` | `Object` | no |  | The arguments of the method. |

Returns: `jQuery` The same element.

The selector has the same forms as in [FIND()](#find). The method can be a nested name such as `nested.run`, and it can also be part of the selector as `selector/method`. With `true` as the first argument, the call waits until a matching component exists.

Example: Call matching components
```html
<div id="panel">
	<ui-component name="counter" path="data.a"></ui-component>
	<ui-component name="counter" path="data.b"></ui-component>
</div>

<script>
COMPONENT('counter', function(self) {
	self.hello = function(name) {
		console.log(self.path, 'hello', name);
	};
});

ON('ready', function() {
	$('#panel').SETTER('counter', 'hello', 'Ann');
	$('#panel').SETTER('.data.b/hello', 'Bob');
});
</script>
```

Example: Wait for a component
```html
<div id="panel"></div>

<script>
$('#panel').SETTER(true, 'late', 'hello', 'Ann');

COMPONENT('late', function(self) {
	self.hello = function(name) {
		console.log('hello', name);
	};
});

$('#panel').append('<ui-component name="late" path="data.late"></ui-component>');
COMPILE();
</script>
```

### el.tclass(name, [state])

Type: `method`

Toggles a class.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The class name. |
| `state` | `Boolean` | no |  | `true` adds the class and `false` removes it. |

Returns: `jQuery` The same element.

Example: Toggle a class
```html
<div id="box"></div>

<script>
var el = $('#box');

el.tclass('open').hclass('open'); // true
el.tclass('open').hclass('open'); // false
el.tclass('open', true).hclass('open'); // true
</script>
```

### el.vbind()

Type: `method`

Returns the virtual binder of an item created by `VBINDARRAY()`.

Returns: `Object` The binder of the item, or `null`.

The element can be the item or an element inside it. See [Virtual binder](../vbinder/).

Example: Read the item binder
```html
<div id="list"></div>

<script>
var list = VBINDARRAY('<div><b data-bind="name__text"></b></div>', $('#list'));
list.set([{ name: 'Ann' }, { name: 'Bob' }]);

$('#list b').last().vbind().index; // 1
</script>
```

### el.vbindarray()

Type: `method`

Returns the object created by `VBINDARRAY()` for the element or its nearest parent.

Returns: `Object` The virtual binder array, or `null`.

See [Virtual binder](../vbinder/).

Example: Read the array binder
```html
<div id="list"></div>

<script>
var list = VBINDARRAY('<div><b data-bind="name__text"></b></div>', $('#list'));
list.set([{ name: 'Ann' }]);

$('#list b').vbindarray() === list; // true
</script>
```

### $.components

Type: `property`

A reference to the global object `M`.

See [M](../m/).

Example: The same object
```js
$.components === M; // true
```
