I am viewing the HTML of Hacker News. For example this post:
https://news.ycombinator.com/item?id=39241448
In the HTML, the tr with athing class has the same id as the expand/collapse button a element:
Rules state that:
https://www.w3schools.com/html/html_id.asp
You cannot have more than one element with the same id in an HTML document.
Am I misunderstanding the rules or is that not valid HTML?
>Solution :
You are correct that this violates that "rule," but HTML parsers tend to be forgiving if they can. If this page tried to use that ID in some way (document.getElementById("39241834")), the behavior would be unclear, but the browser is still able to render this invalid HTML and the page still "works"
You can read more about why browsers accept invalid HTML at this question
