logoalt Hacker News

xg15yesterday at 2:42 PM3 repliesview on HN

Whether you can or can't omit a closing element is one thing, but it seems like a useful thing to be able to quickly determine if some content is inside or outside a tag, so why complicate things?

(This is especially relevant with "void" tags. E.g. if someone wrote "<img> hello </img>" then the "hello" is not contained in the tag. You could use the self closing syntax to make this more obvious -- Edit: That's bad advice, see below.)


Replies

jakelazaroffyesterday at 3:43 PM

The inert self closing syntax is misleading, though, because if you use it for a non-void element then whatever follows will be contained within the tag.

e.g. how do you think a browser will interpret this markup?

    <div />
    <img />
A lot of people think it ends up like this (especially because JSX works this way):

    <div></div>
    <img>
but it's actually equal to this:

    <div>
        <img>
    </div>
show 2 replies
oneeyedpigeonyesterday at 2:55 PM

I absolutely agree. Also, if you want to parse HTML as XML, it's a lot more reliable having it in a known 'good' format to begin with.

mathgeekyesterday at 3:03 PM

This is where I always end up as well. Just because you can do something doesn’t mean you should or shouldn’t.