Dan
Dan

Reputation: 1111

Why doesn't duplicate IDs throw an error?

I did a quick search and couldn't find anything useful for this question. Is there a reason that browsers don't throw a warning or error to the console if there are duplicate IDs on DOM elements? Seems like browsers should realize there are duplicates when they parse your dom structure.

Upvotes: 0

Views: 120

Answers (2)

Quentin
Quentin

Reputation: 943769

Because browser HTML parsers don't perform any debugging functionality whatsoever. They just try to cope with whatever they get as best they can.

End users don't need to know if there is a non-fatal error, and there aren't any fatal errors in HTML. (Throwing a fatal error on a non-well-formed XHTML document was such a popular feature that most (all?) modern browsers will silently switch to an HTML parser instead of displaying the error to the end user).

Developers should use validation tools to QA their work.

Upvotes: 2

Neil Girardi
Neil Girardi

Reputation: 4933

HTML is a markup language, not a programming language. It doesn't have an API which could be used to throw errors.

Upvotes: 1

Related Questions