Search code examples
sveltesvelte-3

How to remove `href` attribute from link with Svelte? Should this be enough?


Am I wrong or this should remove href attribute from the a tag?

<a href={false}></a>

It doesn't ("svelte": "3.44.2").


Solution

  • The docs say

    Boolean attributes are included on the element if their value is truthy and excluded if it's falsy.
    All other attributes are included unless their value is nullish (null or undefined).

    href= is no boolean attribute, so false doesn't work, use null/undefined instead

    <a href={null}>linkText</a>
    <a href={undefined} >linkText</a>