#Changing 'a' element into a 'button' on hydration - best practices?

2 messages · Page 1 of 1 (latest)

summer torrent
#

I'm looking for a "correct/smart" way to turn a <a href...> element into a <button> without causing a layout shift when javascript hydrates. I'm doing it in svelte if that matters. I initially just replaced <a> with <button> when element mounted but that's not ideal. Should I just hijack and modify the <a> like below and maybe add role="button"?

<a href="/contact" class="contact" bind:this={button} on:click={(e) => {
    e.preventDefault();
    // dostuff
  }}
>```

The desired functionality is that I have a working link into a contact page, but when/if the page hydrates it's going to cause a chat window to pop up.
vestal moss
#

Why isn't the on mount method good enough? I haven't used svelte much but am curious.