Part 1 / Events / DOM event forwarding
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>1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script>
import BigRedButton from './BigRedButton.svelte';
import horn from './horn.mp3';
const audio = new Audio();
audio.src = horn;
function handleClick() {audio.play();
}
</script>
<BigRedButton on:click={handleClick} />
initialising