> For the complete documentation index, see [llms.txt](https://cbwire.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbwire.ortusbooks.com/template-directives/wire-click.md).

# wire:click

The `wire:click` directive transforms any HTML element into an interactive control that triggers server-side actions. Instead of traditional page refreshes or complex JavaScript event handling, `wire:click` lets you respond to user clicks by calling component methods directly, creating smooth, dynamic user experiences.

## Basic Usage

This counter component demonstrates `wire:click` with basic actions and parameter passing:

{% tabs %}
{% tab title="BoxLang" %}

```javascript
// wires/ClickDemo.bx
class extends="cbwire.models.Component" {
    data = {
        "count": 0,
        "message": ""
    };

    function increment() {
        data.count++;
    }

    function setMessage(text) {
        data.message = arguments.text;
    }
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// wires/ClickDemo.cfc
component extends="cbwire.models.Component" {
    data = {
        "count" = 0,
        "message" = ""
    };

    function increment() {
        data.count++;
    }

    function setMessage(text) {
        data.message = arguments.text;
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="BoxLang" %}

```html
<!-- wires/clickDemo.bxm -->
<bx:output>
<div>
    <h1>Count: #count#</h1>
    <button wire:click="increment">+</button>
    <button wire:click="setMessage('Hello!')">Say Hello</button>
    <a href="#home" wire:click.prevent="setMessage('Link clicked!')">Click Link</a>
    <p>#message#</p>
</div>
</bx:output>
```

{% endtab %}

{% tab title="CFML" %}

```html
<!-- wires/clickDemo.cfm -->
<cfoutput>
<div>
    <h1>Count: #count#</h1>
    <button wire:click="increment">+</button>
    <button wire:click="setMessage('Hello!')">Say Hello</button>
    <a href="##home" wire:click.prevent="setMessage('Link clicked!')">Click Link</a>
    <p>#message#</p>
</div>
</cfoutput>
```

{% endtab %}
{% endtabs %}

## What wire:click Does

When you add `wire:click` to an element, CBWIRE automatically:

* **Captures Click Events**: Listens for click events on the element without requiring JavaScript
* **Calls Component Methods**: Executes the specified action method in your component
* **Passes Parameters**: Supports passing arguments to your action methods using parentheses syntax
* **Updates UI**: Re-renders the component with any data changes from your action
* **Provides Loading States**: Integrates with `wire:loading` for visual feedback during actions

## Available Modifiers

The `wire:click` directive supports one modifier:

* **Prevent**: `.prevent` - Prevents default browser behavior (essential for links)

Example: `wire:click.prevent="sendEmail"`

{% hint style="info" %}
Use `wire:click` on any HTML element - buttons, links, divs, images, or any clickable element - making it incredibly versatile for building interactive interfaces.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cbwire.ortusbooks.com/template-directives/wire-click.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
