Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempted to close an element that was not open

Tags:

html

svelte

I've got the following code in Svelte. It works without the <p> tag, but when I put the {#if}...{/if} inside a <p> tag, I receive the following error on the last line and the application doesn't compile.

< /p> attempted to close an element that was not open

<p>
   <h3>Active games</h3>
   {#if !Array.isArray(games)}
      <span>Loading...</span>
   {:else if games.length === 0}
      <span>None</span>
   {:else}
      {#each games as game (game.id)}
         <a href={'/game/' + game.id}>{game.name}</a><br>
      {/each}
   {/if}
</p>

What's causing the error?

like image 397
Mielipuoli Avatar asked Nov 29 '25 20:11

Mielipuoli


1 Answers

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p, The "Tag omission" section, p tag is automatically closed if encounter any other block level element, eg <h3> tag in this example.

In other words, you can't have any other block level element within <p> tag.

like image 197
Tan Li Hau Avatar answered Dec 01 '25 11:12

Tan Li Hau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!