Skip to content
Discussion options

You must be logged in to vote

You should write it like this:

<script>
        function test(){
            console.log('test')
        }
</script>

<button on:click={test} class="bg-green-400 p-2">stop</button> 
  • you shouldn't declare your test function in onMount, it should just be at the top of the script tag
  • svelte doesn't use onClick, it uses on:click
  • you need to wrap the event handler in curly brackets, e.g. on:click={test}

I highly recommend going through the event handling section of the tutorial - it seems like you're missing some of the concepts there.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@magic-thomas
Comment options

@ioucyf
Comment options

@magic-thomas
Comment options

@geoffrich
Comment options

Answer selected by magic-thomas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants