---
title: "Rozšírenia jQuery"
project: jComponent V20
version: 20.015
section: reference
language: sk
license: MIT
url: https://totaljs.es/docs/sk/jcomponent-v20/20-015/reference/jquery/
updated: 2026-11-18T13:58:19.462Z
---

# Rozšírenia jQuery

> Metódy, ktoré jComponent pridáva do jQuery na prácu s triedami, atribútmi a SVG, hľadanie inštancií a volanie knižnice.

jComponent obsahuje jQuery a pridáva tieto metódy každému výberu jQuery. Používajú sa najmä vnútri komponentov a pluginov: pozri [Vytváranie komponentov](../../guides/creating-components/) a [Pluginy](../../guides/plugins/).

## API

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

Type: `method`

Pridá triedu CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov triedy. |
| `delay` | `Number` | no |  | Oneskorenie v milisekundách. |

Returns: `jQuery` Ten istý výber.

S `delay` sa trieda pridá neskôr. Každý element uchováva jednu oneskorenú zmenu triedy: nové oneskorené volanie `aclass()`, `rclass()` alebo `rclass2()` nahradí tú, ktorá čaká.

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

Example: Pridanie triedy neskôr
```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`

Pripojí element SVG.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | Názov značky alebo značky SVG. |

Returns: `jQuery` Nový element, keď je `tag` názov značky.

S názvom značky metóda vytvorí element v mennom priestore SVG a vráti ho. `tag` môžu byť aj značky SVG, ktoré sa pripoja k výberu.

Example: Kreslenie
```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`

Prečíta alebo zapíše atribút `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov atribútu bez `data-`. |
| `value` | `Object` | no |  | Hodnota na zápis. |

Returns: `String or jQuery` Pri čítaní hodnota, pri zápise ten istý výber.

Example: Čítanie a zápis
```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`

Prečíta atribút `data-` z elementu alebo z jeho najbližšieho nadradeného elementu, ktorý ho má.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov atribútu bez `data-`. |

Returns: `String` Hodnota, alebo `undefined`, keď atribút nemá žiadny element.

Hľadanie sa končí pri `<body>`.

Example: Hľadanie v nadradených elementoch
```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`

Presunie focus na prvé viditeľné pole vnútri výberu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `input,select,textarea` | Polia, ktoré sa majú prehľadať. |

Returns: `jQuery` Ten istý výber.

Keď focus ešte nemôže prijať žiadne pole, metóda to krátky čas skúša znova. Na mobilných zariadeniach nerobí nič.

Example: Presun focusu do formulára
```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`

Vráti najbližšiu inštanciu [ui-bind](../ui-bind/).

Returns: `Object` Inštancia, alebo `undefined`, keď žiadna nie je.

Hľadanie sa začína pri prvom elemente výberu a pokračuje cez jeho nadradené elementy.

Example: Hľadanie bindera
```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`

Spustí príkaz na komponentoch vnútri výberu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Príkaz, voliteľne s flagmi za ním. |
| `a` | `Object` | no |  | Prvý argument. |
| `b` | `Object` | no |  | Druhý argument. |
| `c` | `Object` | no |  | Tretí argument. |
| `d` | `Object` | no |  | Štvrtý argument. |

Príkaz sa dostane iba ku komponentom vnoreným vo vybraných elementoch. Komponenty registrujú príkazy cez [command()](../component/) a globálne [CMD()](../globals/) sa dostane ku všetkým. Metóda nič nevracia.

Example: Príkaz v jednom paneli
```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`

Vráti najbližšiu inštanciu [Component](../component/).

Returns: `Component` Inštancia, alebo `undefined`, keď žiadna nie je.

Hľadanie sa začína pri prvom elemente výberu a pokračuje cez jeho nadradené elementy.

Example: Hľadanie komponentu
```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`

Vráti pripravené komponenty vnútri výberu.

Returns: `Array` Inštancie [Component](../component/).

Example: Výpis komponentov
```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`

Spustí funkciu, metódu pluginu, udalosť alebo setter komponentu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Čo sa má spustiť. |
| `a` | `Object` | no |  | Prvý argument. |
| `b` | `Object` | no |  | Druhý argument. |
| `c` | `Object` | no |  | Tretí argument. |
| `d` | `Object` | no |  | Štvrtý argument. |

Tvar `name` určuje, čo sa spustí:

| Názov | Čo sa spustí |
| --- | --- |
| `myfunction` | Globálna funkcia |
| `FUNC.path` | Funkcia na path |
| `plugin/method` | Metóda pluginu |
| `?/method`, `\|method` | Metóda najbližšieho pluginu |
| `#name` | Udalosť `name` |
| `-component/method` | Setter komponentu |

Metóda nič nevracia.

Example: Spustenie funkcie
```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`

Overí, či má element triedu CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov triedy. |

Returns: `Boolean` `true`, keď je trieda prítomná.

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

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

Type: `method`

Spustí naraz niekoľko vyhľadávaní vnútri výberu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectors` | `Object` | yes |  | Kľúče výsledku a ich selektory. |

Returns: `Object` Výber jQuery pre každý kľúč.

Example: Hľadanie elementov
```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`

Vráti najbližšiu inštanciu [Plugin](../plugin/).

Returns: `Plugin` Inštancia, alebo `undefined`, keď žiadna nie je.

Hľadanie sa začína pri prvom elemente výberu a pokračuje cez jeho nadradené elementy.

Example: Hľadanie pluginu
```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`

Vloží element SVG na začiatok výberu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tag` | `String` | yes |  | Názov značky alebo značky SVG. |

Returns: `jQuery` Nový element, keď je `tag` názov značky.

S názvom značky metóda vytvorí element v mennom priestore SVG a vráti ho. `tag` môžu byť aj značky SVG, ktoré sa vložia na začiatok výberu.

Example: Vloženie na začiatok
```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`

Odstráni atribút.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov atribútu. |

Returns: `jQuery` Ten istý výber.

Example: Odstránenie atribútu
```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`

Odstráni atribúty `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov atribútu bez `data-`. Každý ďalší argument odstráni ďalší atribút. |

Returns: `jQuery` Ten istý výber.

Example: Odstránenie atribútov
```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`

Odstráni triedu CSS alebo všetky triedy.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | Názov triedy. |
| `delay` | `Number` | no |  | Oneskorenie v milisekundách. |

Returns: `jQuery` Ten istý výber.

Bez `name` sa odstráni každá trieda. S `delay` sa trieda odstráni neskôr a oneskorená zmena funguje ako v `aclass()`.

Example: Odstránenie tried
```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`

Odstráni všetky triedy CSS, ktoré obsahujú text alebo zodpovedajú vzoru.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String or RegExp` | yes |  | Hľadaný text alebo testovaný vzor. |
| `delay` | `Number` | no |  | Oneskorenie v milisekundách. |

Returns: `jQuery` Ten istý výber.

S `delay` sa triedy odstránia neskôr a oneskorená zmena funguje ako v `aclass()`.

Example: Odstránenie podľa textu alebo vzoru
```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`

Vráti najbližší vlastný posuvník vytvorený pomocou [SCROLLBAR()](../globals/).

Returns: `Object` Inštancia posuvníka, alebo `undefined`, keď žiadna nie je.

Hľadanie sa začína pri prvom elemente výberu a pokračuje cez jeho nadradené elementy.

Example: Hľadanie posuvníka
```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`

Spustí funkciu, ak existuje, inak zapíše hodnotu na path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Funkcia alebo path. |
| `a` | `Object` | no |  | Prvý argument alebo hodnota pre path. |
| `b` | `Object` | no |  | Druhý argument. |
| `c` | `Object` | no |  | Tretí argument. |
| `d` | `Object` | no |  | Štvrtý argument. |

Globálna funkcia, `plugin/method` a `?/method` sa zavolajú s argumentmi. Každý iný názov je path a `a` sa naň zapíše pomocou [SET()](../globals/). Metóda nič nevracia.

Example: Funkcia alebo 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`

Zavolá metódu komponentov vnútri výberu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Komponenty a metóda. |
| `a` | `Object` | no |  | Prvý argument. |
| `b` | `Object` | no |  | Druhý argument. |
| `c` | `Object` | no |  | Tretí argument. |
| `d` | `Object` | no |  | Štvrtý argument. |

`name` má tvar `component/method`. Namiesto názvu komponentu `*` vyberie všetky komponenty a `.path` komponenty naviazané na daný path. Metóda nič nevracia.

Example: Volanie komponentov
```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`

Prepne triedu CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov triedy. |
| `enable` | `Boolean` | no |  | `true` triedu pridá a `false` ju odstráni. |

Returns: `jQuery` Ten istý výber.

Example: Prepínanie
```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
```
