Explanation for jQuery
Also, in your case, jQuery should select only one element, and the first element for ID
. Since you have also given div
, it uses getElementsByTagName
, and matches the attribute with ID. So, it returns all the instances. Please correct me if I am wrong.
Suggestion
According to web standards, the id
attribute must be unique. So, each element should have unique ID. If you want to use things for multiple elements, you have classes.
Also, your HTML won't validate, if you have multiple IDs.
Also, from the XHTML 1.0 Spec
In XML, fragment identifiers are of
type ID, and there can only be a
single attribute of type ID per
element. Therefore, in XHTML 1.0 the
id attribute is defined to be of type
ID. In order to ensure that XHTML 1.0
documents are well-structured XML
documents, XHTML 1.0 documents MUST
use the id attribute when defining
fragment identifiers on the elements
listed above. See the HTML
Compatibility Guidelines for
information on ensuring such anchors
are backward compatible when serving
XHTML documents as media type
text/html.