Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But it doesn't even "work for particular names" because the `/>` part isn't what closes the element.

By the time the parser has seen the sequence `<br` it already knows which element this is, because it can only be the BR element, and has already finalized the DOM node for it because that's the rule for the BR tag. The moment it sees the opening angled bracket and tag, that node is created in an already closed state.

So those extra two `/>` do, in the most literal sense possible, nothing at all. They're allowed to be there for historical reason but they literally do nothing: they're treated as bytes to be ignored and the DOM parser skips over them while it looks for the next active token in order to continue building the DOM.



If this were true, I'd expect this HTML:

    <p>A<br B</p>
    <p>C</p>
To render as this:

    A
    B
    C

But instead it renders as this:

    A
    C
The parser treats `B<` and `p` as attributes of `br`, and determines that the `<br` tag ends with the `>` at the end of line 1.

If I end the `<br` with either `/>` or `>`, it parses correctly. Which means that `/>` and `>` are both considered valid endings for the `<br` tag, but you have to have one or the other and it will keep looking until it finds one.


Right, I think the person you’re replying to is partially correct in that the parser gets to “<br “ and recognizes that “this is be a br tag”, but it doesn’t close because tags can have any arbitrary attributes, and the W3C says br may also contain any of the global attributes. So, the parser indeed doesn’t just stop because it knows what tag it is and then doesn’t allow any attributes, it has to keep going until it reaches a valid closing “>”.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: