If there is something to add to the previous good answers, it is to explain why id
s must be unique per page. This is important to understand for a beginner because applying the same id
to multiple elements within the same page will not trigger any error and rather has the same effects as a class
.
So from an HTML/CSS perspective, the uniqueness of id
per page does not make a sens. But from the JavaScript perspective, it is important to have one id
per element per page because getElementById()
identifies, as its name suggests, elements by their id
s.
So even if you are a pure HTML/CSS developer, you must respect the uniqueness aspect of id
s per page for two good reasons: