---
title: Click actions
project: jComponent V20
version: 20.016
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-016/reference/click-actions/
updated: 2026-12-02T17:12:40.807Z
---

# Click actions

> The classes and the data attributes that call a function or change the URL on a click, a double click and a right click.

The library handles three CSS classes in the whole page, also in elements added later: `exec` for a click, `exec2` for a double click and `exec3` for a click with the right button. What happens is written in `data-` attributes. An introduction with examples is in the guide [Click actions](../../guides/click-actions/).

When a component named `exec` is declared in the page, it takes over this work and the library does nothing.

## API

### data-exec="name"

Type: `property`

Calls a function when an element with the class `exec` is clicked.

The function receives the element as a jQuery object and the event. The name has the forms of [$(selector).EXEC()](../jquery/):

| Name | Calls |
| --- | --- |
| `FUNC.name` | A function found at a path |
| `?/method` | A method of the closest plugin |
| `plugin/method` | A method of a plugin |
| `@method` | A method of the closest component. It receives the component ahead of the element and the event |
| `-component/method` | A component method |
| `&command` | A command of components |
| `#event` | An event |

Example: Call a function
```html
<button id="save" class="exec" data-exec="FUNC.save">Save</button>

<script>
FUNC.save = function(element, e) {
	console.log(element.attr('id'), e.type); // save click
};

ON('ready', () => $('#save').trigger('click'));
</script>
```

Example: Call the closest component
```html
<ui-component name="box"><button id="close" class="exec" data-exec="@close">Close</button></ui-component>

<script>
COMPONENT('box', function(self) {
	self.close = function(component, element) {
		console.log(component.name, element.attr('id')); // box close
	};
});

setTimeout(() => $('#close').trigger('click'), 300);
</script>
```

### data-href="url"

Type: `property`

Changes the URL when an element with the class `exec` is clicked.

The address is passed to [REDIRECT()](../routing/). With `data-exec` on the same element, the function runs first.

Example: Open a page of the application
```html
<button id="orders" class="exec" data-href="/orders/">Orders</button>

<script>
ROUTE('/orders/', function() {
	console.log('orders'); // orders
});

setTimeout(() => $('#orders').trigger('click'), 300);
</script>
```

### data-prevent="true"

Type: `property`

Stops the default action of the browser and the propagation of the click.

The values are `true` and `1`. Use it for links and for buttons that submit a form.

Example: A link that calls a function
```html
<a id="help" class="exec" data-exec="FUNC.help" data-prevent="true" href="/help/">Help</a>

<script>
FUNC.help = function(element, e) {
	console.log(e.isDefaultPrevented()); // true
};

ON('ready', () => $('#help').trigger('click'));
</script>
```

### data-exec2="name"

Type: `property`

Calls a function when an element with the class `exec2` is double-clicked.

The names and the arguments are those of `data-exec`. `data-href2` and `data-prevent2` work in the same way for the double click.

An element can have both classes, `exec` and `exec2`. A click then waits 300 milliseconds, and a double click in that time calls only the function of `data-exec2`.

Example: A double click
```html
<div id="row" class="exec2" data-exec2="FUNC.open">Row</div>

<script>
FUNC.open = function(element, e) {
	console.log(element.attr('id'), e.type); // row dblclick
};

ON('ready', () => $('#row').trigger('dblclick'));
</script>
```

### data-exec3="name"

Type: `property`

Calls a function when an element with the class `exec3` is clicked with the right button.

The names and the arguments are those of `data-exec`, and `data-href3` changes the URL. The menu of the browser is not displayed.

Example: A menu of your own
```html
<div id="file" class="exec3" data-exec3="FUNC.menu">File</div>

<script>
FUNC.menu = function(element, e) {
	console.log(element.attr('id'), e.isDefaultPrevented()); // file true
};

ON('ready', () => $('#file').trigger('contextmenu'));
</script>
```
