26 ms·
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 outs
by xg15 10mo ago
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.)
- oneeyedpigeon 10mo agoI 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.
- mathgeek 10mo agoThis is where I always end up as well. Just because you can do something doesn’t mean you should or shouldn’t.
- jakelazaroff 10mo agoThe 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>
- xg15 10mo agoAh, that's true. I think the WHATWG discouraged the syntax, so this might be why.
- ricardobeat 10mo agoThis is really easy to detect though, unlike arbitrary rules on what belongs on the inside of an unclosed tag.