Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How can I pass parameters to on:click in Svelte?

$
0
0

Binding a function to a button is easy and straightforward:

<button on:click={handleClick}>    Clicks are handled by the handleClick function!</button>

But I don't see a way to pass parameters (arguments) to the function, when I do this:

<button on:click={handleClick("parameter1")}>    Oh no!</button>

The function is called on page load, and never again.

Is it possible at all to pass parameters to function called from on:click{}?


I found the proper way to do it (see comments). Calling the function from an inline handler works.

<button on:click={() => handleClick("parameter1")}>    It works...</button>

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>