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

# Estensioni di jQuery

> Metodi che jComponent aggiunge a jQuery per lavorare con classi, attributi, SVG, componenti e scope.

jComponent include jQuery e aggiunge questi metodi a `$.fn`, quindi funzionano su ogni oggetto jQuery. La pagina [Componente](../component/) descrive gli oggetti restituiti dai metodi dei componenti e [Uso dei componenti](../../guides/using-components/) spiega come si dichiarano i componenti.

## API

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

Type: `method`

Aggiunge una o più classi, subito o dopo un ritardo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | I nomi delle classi, separati da spazi. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` Lo stesso elemento.

Le chiamate ritardate condividono un solo timer per elemento, quindi una nuova chiamata ritardata di `aclass()`, `rclass()` o `rclass2()` annulla quella ancora in attesa.

Example: Aggiungi una classe
```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`

Aggiunge un elemento SVG all'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | Un nome di tag o markup SVG. |

Returns: `jQuery` Il nuovo elemento, quando `tag` è un nome di tag.

Un nome di tag crea un elemento nel namespace SVG e lo restituisce. Un testo con markup aggiunge tutti i suoi elementi; usa un nome di tag quando ti serve il nuovo elemento in seguito.

Example: Aggiungi elementi SVG
```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`

Legge o scrive un attributo `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'attributo senza il prefisso `data-`. |
| `value` | `Object` | no |  | Il nuovo valore. |

Returns: `String or jQuery` Il valore in lettura, lo stesso elemento in scrittura.

Example: Attributi data
```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`

Legge un attributo `data-` dall'elemento o dal genitore più vicino che lo possiede.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'attributo senza il prefisso `data-`. |

Returns: `String` Il valore, oppure `undefined`.

Example: Eredita un valore
```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`

Sposta il focus sul primo campo visibile dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `'input,select,textarea'` | I campi da cercare. |

Returns: `jQuery` Lo stesso elemento.

Quando nessun campo può ricevere il focus, il metodo riprova ogni 200 millisecondi, fino a 15 volte. Sui dispositivi mobili non fa nulla.

Example: Dai il focus a un 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`

Restituisce il binder dell'elemento o del genitore più vicino.

Returns: `Object` Il binder, oppure `null`.

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

Example: Leggi un 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`

Esegue un comando in tutti i componenti dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome del comando. |
| `a` | `Object` | no |  | Il primo di un massimo di cinque argomenti per il comando. |

I componenti registrano i comandi con `self.command()`. Vedi [Componente](../component/).

Example: Esegui un comando
```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`

Restituisce il componente dell'elemento o del genitore più vicino.

Returns: `Component` Il componente, oppure `null`.

Example: Trova il componente padre
```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`

Elenca o percorre i componenti pronti dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | no |  | Chiamata per ogni componente. |

Returns: `Array or jQuery` Senza `fn`, un array di componenti, oppure `null` quando non ce ne sono. Con `fn`, gli elementi dei componenti.

Con `fn`, la funzione viene chiamata con il componente come `this` e la posizione del suo elemento come argomento.

Example: Percorri i componenti
```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`

Chiama un metodo sui componenti dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome del metodo, eventualmente con il prefisso `^`. |
| `args` | `Object` | no |  | Gli argomenti del metodo. |

Returns: `jQuery` Lo stesso elemento.

Con il prefisso `^`, il metodo viene chiamato sui componenti degli elementi genitori. I componenti privi del metodo vengono saltati.

Example: Chiama un metodo
```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: Chiama un metodo sui genitori
```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`

Trova i componenti dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `many` | `Boolean` | no |  | Usa `true` per ottenere tutti i componenti corrispondenti. |
| `callback` | `Function` | no |  | Riceve il risultato quando è disponibile. |
| `timeout` | `Number` | no |  | Il tempo massimo di attesa in millisecondi. |

Returns: `Component, Array or jQuery` Il primo componente, oppure un array con `many`. Con `callback`, lo stesso elemento.

Il selettore può essere un nome di componente, `name[path]`, `.path`, `#id` o `*`.

Con `callback`, il metodo attende che esista un componente e poi chiama `callback(component)`, con il componente anche come `this`. Se `timeout` scade prima, il callback non viene chiamato. Puoi omettere `many` quando passi un callback.

Example: Trova i componenti
```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: Attendi un componente
```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`

Controlla se l'elemento ha una classe.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome della classe. |

Returns: `Boolean` `true` quando la classe è presente.

Example: Controlla una classe
```html
<div id="box" class="active"></div>

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

### el.multiple(selectors)

Type: `method`

Esegue più chiamate di `find()` e restituisce i risultati sotto i rispettivi nomi.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectors` | `Object` | yes |  | Nomi e selettori. |

Returns: `Object` Oggetti jQuery sotto gli stessi nomi.

Example: Trova più elementi
```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`

Restituisce il plugin che contiene l'elemento.

Returns: `Plugin` Il plugin, oppure `undefined`.

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

Example: Raggiungi un 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`

Antepone un elemento SVG all'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | Un nome di tag o markup SVG. |

Returns: `jQuery` Il nuovo elemento, quando `tag` è un nome di tag.

Funziona come [asvg()](#asvg), ma il nuovo contenuto viene inserito per primo.

Example: Anteponi un elemento SVG
```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`

Rimuove un attributo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'attributo. |

Returns: `jQuery` Lo stesso elemento.

Example: Rimuovi un attributo
```html
<div id="box" title="Hello"></div>

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

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

Type: `method`

Rimuove uno o più attributi `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | I nomi degli attributi senza il prefisso `data-`. |

Returns: `jQuery` Lo stesso elemento.

Example: Rimuovi gli attributi data
```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`

Rimuove le classi, subito o dopo un ritardo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | I nomi delle classi, separati da spazi. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` Lo stesso elemento.

Senza un nome, vengono rimosse tutte le classi. Le chiamate ritardate condividono un solo timer per elemento, quindi una nuova chiamata ritardata di `aclass()`, `rclass()` o `rclass2()` annulla quella ancora in attesa.

Example: Rimuovi le classi
```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`

Rimuove le classi che contengono un testo o corrispondono a un'espressione regolare.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String or RegExp` | yes |  | Il testo da cercare o un'espressione regolare. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` Lo stesso elemento.

Le chiamate ritardate condividono un solo timer per elemento, quindi una nuova chiamata ritardata di `aclass()`, `rclass()` o `rclass2()` annulla quella ancora in attesa.

Example: Rimuovi in base a un modello
```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`

Cambia la configurazione dei componenti dentro l'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `value` | `String or Object` | yes |  | La nuova configurazione. |

Returns: `jQuery` Lo stesso elemento.

Il selettore ha le stesse forme di [FIND()](#find).

Example: Riconfigura i componenti
```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`

Restituisce lo scope che contiene l'elemento.

Returns: `Scope` Lo scope. Fuori da uno scope, il risultato è vuoto.

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

Example: Leggi il path dello scope
```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`

Chiama un metodo sui componenti dentro l'elemento che corrispondono a un selettore.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `wait` | `Boolean` | no |  | Usa `true` per attendere il componente. |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `method` | `String` | yes |  | Il nome del metodo. |
| `args` | `Object` | no |  | Gli argomenti del metodo. |

Returns: `jQuery` Lo stesso elemento.

Il selettore ha le stesse forme di [FIND()](#find). Il metodo può essere un nome annidato come `nested.run` e può anche far parte del selettore come `selector/method`. Con `true` come primo argomento, la chiamata attende che esista un componente corrispondente.

Example: Chiama i componenti corrispondenti
```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: Attendi un componente
```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`

Attiva o disattiva una classe.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome della classe. |
| `state` | `Boolean` | no |  | `true` aggiunge la classe e `false` la rimuove. |

Returns: `jQuery` Lo stesso elemento.

Example: Attiva o disattiva una classe
```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`

Restituisce il binder virtuale di un elemento creato da `VBINDARRAY()`.

Returns: `Object` Il binder della voce, oppure `null`.

L'elemento può essere la voce stessa o un elemento al suo interno. Vedi [Binder virtuale](../vbinder/).

Example: Leggi il binder della voce
```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`

Restituisce l'oggetto creato da `VBINDARRAY()` per l'elemento o per il genitore più vicino.

Returns: `Object` L'array di binder virtuali, oppure `null`.

Vedi [Binder virtuale](../vbinder/).

Example: Leggi il binder dell'array
```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`

Un riferimento all'oggetto globale `M`.

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

Example: Lo stesso oggetto
```js
$.components === M; // true
```
