Part 1 / Events / DOM event forwarding
Event forwarding works for DOM events too.
We want to get notified of clicks on our <CustomButton>
— to do that, we just need to forward click
events on the <button>
element in CustomButton.svelte
:
<button on:click>
Click me
</button>
1
2
3
4
5
6
7
8
9
10
<script>
import CustomButton from './CustomButton.svelte';
function handleClick() {
alert('Button Clicked');
}
</script>
<CustomButton on:click={handleClick} />
initialising