I’m using Svelte 5.
<a href="my-first-link">
<div>
<!-- Some elements -->
</div>
<a href="my-second-link">
<div>
<!-- Some other elements -->
</div>
</a>
<div>
<!-- Some elements -->
</div>
</a>
Svelte is throwing a lint error:
`<a>` is invalid inside `<a>`svelte(node_invalid_placement)
What is expected in this situation to fix this issue?
2
Answers
That’s expected. You can’t have interactive content inside an
<a>
tag. Since<a>
tags are interactive elements themself, you can’t nest them. You’ll have to redesign your markup to account for this.https://html.spec.whatwg.org/#interactive-content
It is not possible to stack elements inside of each other directly in Svelte. You must reorganize your structure so that every link is independent in order to fix the lint mistake. This is one method of code refactoring:
To avoid the invalid nesting, move the second tag outside of the first one. Now, every link can function independently.