---
title: Estensioni di jQuery
project: jComponent V20
version: 20.015
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v20/20-015/reference/jquery/
updated: 2026-11-18T13:58:19.462Z
---

# Estensioni di jQuery

> I metodi che jComponent aggiunge a jQuery per classi, attributi, SVG, ricerca delle istanze e chiamate alla libreria.

jComponent include jQuery e aggiunge questi metodi a ogni selezione jQuery. Si usano soprattutto all'interno di componenti e plugin: vedi [Creare componenti](../../guides/creating-components/) e [Plugin](../../guides/plugins/).

## API

### $(selector).aclass(name, [delay])

Type: `method`

Aggiunge una classe CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome della classe. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` La stessa selezione.

Con `delay`, la classe viene aggiunta in seguito. Ogni elemento conserva una sola modifica di classe ritardata: una nuova chiamata ritardata di `aclass()`, `rclass()` o `rclass2()` sostituisce quella in attesa.

Example: Aggiungere una classe
```js
var el = $('<div>');
el.aclass('active');
console.log(el.attr('class')); // active
```

Example: Aggiungere una classe in seguito
```js
var el = $('<div>');
el.aclass('active', 50);
console.log(el.hclass('active')); // false
setTimeout(function() {
	console.log(el.hclass('active')); // true
}, 100);
```

### $(selector).asvg(tag)

Type: `method`

Aggiunge un elemento SVG.

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

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

Con il nome di un tag, il metodo crea l'elemento nel namespace SVG e lo restituisce. `tag` può essere anche markup SVG, che viene aggiunto alla selezione.

Example: Disegnare
```js
var svg = $('<svg></svg>');
var circle = svg.asvg('circle');
circle.attr('r', 5);
svg.asvg('<rect width="5"></rect>');
console.log(circle[0].namespaceURI); // http://www.w3.org/2000/svg
console.log(svg.html()); // <circle r="5"></circle><rect width="5"></rect>
```

### $(selector).attrd(name, [value])

Type: `method`

Legge o scrive un attributo `data-`.

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

Returns: `String or jQuery` Il valore in lettura, oppure la stessa selezione in scrittura.

Example: Leggere e scrivere
```js
var el = $('<div data-id="7">');
console.log(el.attrd('id')); // 7
el.attrd('name', 'box');
console.log(el.attr('data-name')); // box
```

### $(selector).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 `data-`. |

Returns: `String` Il valore, oppure `undefined` quando nessun elemento ha l'attributo.

La ricerca termina in `<body>`.

Example: Cercare tra i genitori
```html
<div data-id="7"><span><b id="item"></b></span></div>
<script>
console.log($('#item').attrd2('id')); // 7
console.log($('#item').attrd2('missing') === undefined); // true
</script>
```

### $(selector).autofocus([selector])

Type: `method`

Sposta il focus sul primo campo visibile all'interno della selezione.

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

Returns: `jQuery` La stessa selezione.

Il metodo riprova per un breve periodo quando nessun campo può ancora ricevere il focus. Sui dispositivi mobili non fa nulla.

Example: Dare il focus a un modulo
```html
<div id="form"><input id="code" type="hidden"><input id="name"></div>
<script>
$('#form').autofocus();
console.log(document.activeElement.id); // name
</script>
```

### $(selector).binder()

Type: `method`

Restituisce l'istanza di [ui-bind](../ui-bind/) più vicina.

Returns: `Object` L'istanza, oppure `undefined` quando non ce n'è nessuna.

La ricerca parte dal primo elemento della selezione e risale attraverso i suoi genitori.

Example: Trovare il binder
```html
<ui-bind id="title" path="common.title" config="text"></ui-bind>
<script>
setTimeout(function() {
	console.log($('#title').binder().element[0].tagName); // UI-BIND
	console.log($('body').binder() === undefined); // true
}, 300);
</script>
```

### $(selector).CMD(name, [a], [b], [c], [d])

Type: `method`

Esegue un comando sui componenti all'interno della selezione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il comando, eventualmente seguito da flag. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

Vengono raggiunti solo i componenti annidati negli elementi selezionati. I componenti registrano i comandi con [command()](../component/) e la funzione globale [CMD()](../globals/) li raggiunge tutti. Il metodo non restituisce nulla.

Example: Un comando in un solo pannello
```html
<div id="left"><ui-component name="list" id="a"></ui-component></div>
<div id="right"><ui-component name="list" id="b"></ui-component></div>
<script>
COMPONENT('list', function(self) {
	self.command('clear', () => console.log('clear', self.element.attr('id')));
});
ON('ready', function() {
	$('#left').CMD('clear'); // clear a
});
</script>
```

### $(selector).component()

Type: `method`

Restituisce l'istanza di [Componente](../component/) più vicina.

Returns: `Component` L'istanza, oppure `undefined` quando non ce n'è nessuna.

La ricerca parte dal primo elemento della selezione e risale attraverso i suoi genitori.

Example: Trovare il componente
```html
<ui-component name="note" path="common.note"><b id="label"></b></ui-component>
<script>
COMPONENT('note', function(self) {});
setTimeout(function() {
	console.log($('#label').component().name); // note
	console.log($('body').component() === undefined); // true
}, 300);
</script>
```

### $(selector).COMPONENTS()

Type: `method`

Restituisce i componenti pronti all'interno della selezione.

Returns: `Array` Le istanze di [Componente](../component/).

Example: Elencare i componenti
```html
<div id="left"><ui-component name="note" path="common.a"></ui-component></div>
<div id="right"><ui-component name="note" path="common.b"></ui-component></div>
<script>
COMPONENT('note', function(self) {});
setTimeout(function() {
	console.log($('body').COMPONENTS().length); // 2
	console.log($('#left').COMPONENTS()[0].path.toString()); // common.a
}, 300);
</script>
```

### $(selector).EXEC(name, [a], [b], [c], [d])

Type: `method`

Esegue una funzione, un metodo di un plugin, un evento o un setter di un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Che cosa eseguire. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

La forma di `name` stabilisce che cosa viene eseguito:

| Nome | Che cosa viene eseguito |
| --- | --- |
| `myfunction` | Una funzione globale |
| `FUNC.path` | La funzione in un path |
| `plugin/method` | Un metodo di un plugin |
| `?/method`, `\|method` | Un metodo del plugin più vicino |
| `#name` | L'evento `name` |
| `-component/method` | Un setter di un componente |

Il metodo non restituisce nulla.

Example: Eseguire una funzione
```html
<ui-plugin path="orders"><button id="save"></button></ui-plugin>
<script>
var out = [];
PLUGIN('orders', function(exports) {
	exports.save = id => out.push('save ' + id);
});
FUNC.hello = name => out.push('hello ' + name);
ON('saved', id => out.push('event ' + id));
setTimeout(function() {
	var button = $('#save');
	button.EXEC('FUNC.hello', 'Ana');
	button.EXEC('orders/save', 1);
	button.EXEC('?/save', 2);
	button.EXEC('|save', 3);
	button.EXEC('#saved', 4);
	console.log(out); // ["hello Ana","save 1","save 2","save 3","event 4"]
}, 300);
</script>
```

### $(selector).hclass(name)

Type: `method`

Controlla se l'elemento ha una classe CSS.

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

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

Example: Controllare una classe
```js
var el = $('<div class="active">');
console.log(el.hclass('active')); // true
console.log(el.hclass('hidden')); // false
```

### $(selector).multiple(selectors)

Type: `method`

Esegue più ricerche contemporaneamente all'interno della selezione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectors` | `Object` | yes |  | Le chiavi del risultato e i relativi selettori. |

Returns: `Object` Una selezione jQuery per ogni chiave.

Example: Trovare gli elementi
```js
var el = $('<div><input><input><button></button></div>');
var found = el.multiple({ fields: 'input', submit: 'button' });
console.log(found.fields.length); // 2
console.log(found.submit.length); // 1
```

### $(selector).plugin()

Type: `method`

Restituisce l'istanza di [Plugin](../plugin/) più vicina.

Returns: `Plugin` L'istanza, oppure `undefined` quando non ce n'è nessuna.

La ricerca parte dal primo elemento della selezione e risale attraverso i suoi genitori.

Example: Trovare il plugin
```html
<ui-plugin path="orders"><b id="label"></b></ui-plugin>
<script>
PLUGIN('orders', function(exports) {});
setTimeout(function() {
	console.log($('#label').plugin().name); // orders
	console.log($('body').plugin() === undefined); // true
}, 300);
</script>
```

### $(selector).psvg(tag)

Type: `method`

Inserisce un elemento SVG all'inizio della selezione.

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

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

Con il nome di un tag, il metodo crea l'elemento nel namespace SVG e lo restituisce. `tag` può essere anche markup SVG, che viene inserito all'inizio della selezione.

Example: Inserire all'inizio
```js
var svg = $('<svg><line></line></svg>');
var group = svg.psvg('g');
svg.psvg('<path></path>');
console.log(group[0].tagName); // g
console.log(svg.html()); // <path></path><g></g><line></line>
```

### $(selector).rattr(name)

Type: `method`

Rimuove un attributo.

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

Returns: `jQuery` La stessa selezione.

Example: Rimuovere un attributo
```js
var el = $('<div title="x" id="a">');
el.rattr('title');
console.log(el[0].outerHTML); // <div id="a"></div>
```

### $(selector).rattrd(name, [name2], [...])

Type: `method`

Rimuove gli attributi `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'attributo senza `data-`. Ogni argomento successivo rimuove un altro attributo. |

Returns: `jQuery` La stessa selezione.

Example: Rimuovere gli attributi
```js
var el = $('<div data-a="1" data-b="2" data-c="3">');
el.rattrd('a', 'b');
console.log(el[0].outerHTML); // <div data-c="3"></div>
```

### $(selector).rclass([name], [delay])

Type: `method`

Rimuove una classe CSS, oppure tutte.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | Il nome della classe. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` La stessa selezione.

Senza `name`, vengono rimosse tutte le classi. Con `delay`, la classe viene rimossa in seguito, e la modifica ritardata funziona come in `aclass()`.

Example: Rimuovere le classi
```js
var el = $('<div class="a b c">');
el.rclass('a');
console.log(el.attr('class')); // b c
el.rclass();
console.log(el.attr('class') === ''); // true
```

### $(selector).rclass2(search, [delay])

Type: `method`

Rimuove tutte le classi CSS che contengono un testo o che corrispondono a un pattern.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String or RegExp` | yes |  | Il testo da trovare o il pattern da verificare. |
| `delay` | `Number` | no |  | Il ritardo in millisecondi. |

Returns: `jQuery` La stessa selezione.

Con `delay`, le classi vengono rimosse in seguito, e la modifica ritardata funziona come in `aclass()`.

Example: Rimuovere per testo o pattern
```js
var el = $('<div class="tab-1 tab-2 box">');
el.rclass2('tab-');
console.log(el.attr('class')); // box
var other = $('<div class="tab-1 tab-2 box">');
other.rclass2(/1$/);
console.log(other.attr('class')); // tab-2 box
```

### $(selector).scrollbar()

Type: `method`

Restituisce la barra di scorrimento personalizzata più vicina creata con [SCROLLBAR()](../globals/).

Returns: `Object` L'istanza della barra di scorrimento, oppure `undefined` quando non ce n'è nessuna.

La ricerca parte dal primo elemento della selezione e risale attraverso i suoi genitori.

Example: Trovare la barra di scorrimento
```html
<div id="area" style="height:50px"><p id="text"></p></div>
<script>
var scrollbar = SCROLLBAR($('#area'));
console.log($('#text').scrollbar() === scrollbar); // true
console.log($('body').scrollbar() === undefined); // true
</script>
```

### $(selector).SEEX(name, [a], [b], [c], [d])

Type: `method`

Esegue una funzione se esiste, altrimenti scrive un valore in un path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | La funzione o il path. |
| `a` | `Object` | no |  | Il primo argomento, oppure il valore per il path. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

Una funzione globale, `plugin/method` e `?/method` vengono chiamati con gli argomenti. Qualsiasi altro nome è un path, in cui `a` viene scritto con [SET()](../globals/). Il metodo non restituisce nulla.

Example: Funzione o path
```html
<ui-plugin path="orders"><button id="save"></button></ui-plugin>
<script>
var out = [];
PLUGIN('orders', function(exports) {
	exports.save = (a, b) => out.push(a + b);
});
window.hello = name => out.push('hello ' + name);
setTimeout(function() {
	var button = $('#save');
	button.SEEX('hello', 'Ana');
	button.SEEX('?/save', 1, 2);
	button.SEEX('common.count', 5);
	console.log(out); // ["hello Ana",3]
	console.log(GET('common.count')); // 5
}, 300);
</script>
```

### $(selector).SETTER(name, [a], [b], [c], [d])

Type: `method`

Chiama un metodo dei componenti all'interno della selezione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | I componenti e il metodo. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

`name` ha la forma `component/method`. Al posto del nome del componente, `*` seleziona tutti i componenti e `.path` seleziona i componenti associati a quel path. Il metodo non restituisce nulla.

Example: Chiamare i componenti
```html
<div id="left"><ui-component name="note" path="common.a" config="label:A"></ui-component></div>
<div id="right"><ui-component name="note" path="common.b" config="label:B"></ui-component></div>
<script>
var out = [];
COMPONENT('note', function(self, config) {
	self.show = text => out.push(config.label + ' ' + text);
});
setTimeout(function() {
	$('#left').SETTER('note/show', 'one');
	$('body').SETTER('*/show', 'two');
	$('body').SETTER('.common.b/show', 'three');
	console.log(out); // ["A one","A two","B two","B three"]
}, 300);
</script>
```

### $(selector).tclass(name, [enable])

Type: `method`

Attiva o disattiva una classe CSS.

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

Returns: `jQuery` La stessa selezione.

Example: Attivare e disattivare
```js
var el = $('<div>');
el.tclass('open');
console.log(el.hclass('open')); // true
el.tclass('open');
console.log(el.hclass('open')); // false
el.tclass('open', true);
console.log(el.hclass('open')); // true
```
