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

How can I remove and re-add a click listener in Svelte?

$
0
0
<div on:click={handleClick}>Click here</div>

Sometimes I want the div to be clickable, and sometimes I don't. How can I remove and add the click listener on demand?

This is the workaround that I used and it's working for now, but I feel like there must be a more elegant or sveltelcious way of doing it.

let disabled = false;function handleClick() {  if (disabled) return;  // do stuff otherwise}

Viewing all articles
Browse latest Browse all 1541

Trending Articles



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