# lace:click and events

Call component methods or set properties in response to DOM events. `lace:click` is the common case,
but the same directive binds **any DOM event** as `lace:<event>`.

```interlace-demo
ClickDemo
```

## Syntax

```django
<button lace:click="method_name">Click</button>
<button lace:click="method_name('arg')">With an argument</button>
<button lace:click="property = value">Set a property</button>
<button lace:click="$refresh">Re-render only, no method</button>
```

## Any DOM event

Bind any event as `lace:<event>`: `click`, `dblclick`, `submit`, `keydown`, `keyup`, `change`,
`input`, `focus`, `blur`, `mouseenter`, `mouseleave`, `mousedown`, `mouseup`.

```django
<form lace:submit="save">...</form>          {# submit auto-prevents the native page reload #}
<input lace:keydown.enter="send">
<select lace:change="pick">...</select>
<div lace:mouseenter="preview(3)">...</div>
```

## Modifiers

| Modifier | Behavior |
|---|---|
| (none) | call the method or set the property |
| `.prevent` | `event.preventDefault()` (automatic for `lace:submit`) |
| `.stop` | `event.stopPropagation()` |
| `.self` | only when the event target is this element, not a descendant |
| `.once` | run at most once |
| `.enter` `.escape` `.tab` `.up` `.down` ... | on `keydown`/`keyup`, only fire for that key |
| `.renderless` | run the method on the server but skip the re-render/morph (side-effect actions) |
| `.preserve-scroll` | keep the window scroll position steady across the resulting update |

```django
<button lace:click.stop.self="pick">Pick</button>
<input lace:keydown.enter="send">
<button lace:click.renderless="track_view">Log</button>
<button lace:click.preserve-scroll="load_more">Load more</button>
```

See also [lace:confirm](/docs/lace-confirm/) to gate an action behind a confirmation dialog.
