You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/02-template-syntax/05-element-directives.md
+35-8Lines changed: 35 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,12 @@ As well as attributes, elements can have _directives_, which control the element
7
7
## on:_eventname_
8
8
9
9
```svelte
10
+
<!--- copy: false --->
10
11
on:eventname={handler}
11
12
```
12
13
13
14
```svelte
15
+
<!--- copy: false --->
14
16
on:eventname|modifiers={handler}
15
17
```
16
18
@@ -72,7 +74,6 @@ If the `on:` directive is used without a value, the component will _forward_ the
72
74
It's possible to have multiple event listeners for the same event:
73
75
74
76
```svelte
75
-
<!--- file: App.svelte --->
76
77
<script>
77
78
let counter = 0;
78
79
function increment() {
@@ -91,6 +92,7 @@ It's possible to have multiple event listeners for the same event:
91
92
## bind:_property_
92
93
93
94
```svelte
95
+
<!--- copy: false --->
94
96
bind:property={variable}
95
97
```
96
98
@@ -186,6 +188,8 @@ Elements with the `contenteditable` attribute support the following bindings:
186
188
187
189
There are slight differences between each of these, read more about them [here](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#Differences_from_innerText).
188
190
191
+
<!-- for some reason puts the comment and html on same line -->
Actions are functions that are called when an element is created. They can return an object with a `destroy` method that is called after the element is unmounted:
412
421
413
422
```svelte
414
-
<!--- file: App.svelte --->
415
423
<script>
416
424
/** @type {import('svelte/action').Action} */
417
425
function foo(node) {
@@ -433,7 +441,6 @@ An action can have a parameter. If the returned value has an `update` method, it
433
441
> Don't worry about the fact that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition.
434
442
435
443
```svelte
436
-
<!--- file: App.svelte --->
437
444
<script>
438
445
export let bar;
439
446
@@ -461,30 +468,37 @@ Read more in the [`svelte/action`](/docs/svelte-action) page.
0 commit comments