Skip to main content

Event forwarding works for DOM events too.

We want to get notified of clicks on our <BigRedButton> — to do that, we just need to forward click events on the <button> element in BigRedButton.svelte:

BigRedButton.svelte
<button on:click>
	Push
</button>

Next: Bindings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
	import BigRedButton from './BigRedButton.svelte';
	import horn from './horn.mp3';
 
	const audio = new Audio();
	audio.src = horn;
 
	function handleClick() {
		audio.load();
		audio.play();
	}
</script>
 
<BigRedButton on:click={handleClick} />
 
initialising