Line 9, Column 14: Duplicate ID x. <div id="x">was</div>
Warning Line 8, Column 14: The first occurrence of ID x was here. <div id="x">Barry</div>
Error Line 10, Column 14: Duplicate ID x. <div id="x">here</div>
Warning Line 8, Column 14: The first occurrence of ID x was here. <div id="x">Barry</div>
... but the OP specifically stated - what about different element types. So consider the following HTML...
And for what it's worth, on Chrome 26.0.1410.65, Firefox 19.0.2, and Safari 6.0.3 at least, if you have multiple elements with the same ID, jquery selectors (at least) will return the first element with that ID.
e.g.
<div id="one">first text for one</div>
<div id="one">second text for one</div>
Well, using the HTML validator at w3.org, specific to HTML5, IDs must be unique
Consider the following...
the validator responds with ...
... but the OP specifically stated - what about different element types. So consider the following HTML...
... the result from the validator is...
Conclusion:
In either case (same element type, or different element type), if the id is used more than once it is not considered valid HTML5.
I think there is a difference between whether something SHOULD be unique or MUST be unique (i.e. enforced by web browsers).
Should IDs be unique? YES.
Must IDs be unique? NO, at least IE and FireFox allow multiple elements to have the same ID.
Nope, IDs have to be unique. You can use classes for that purpose
Is it possible to have more than one student in a class having same Roll/Id no? In HTML
id
attribute is like so. You may use same class for them. e.g:And so on.
And for what it's worth, on Chrome 26.0.1410.65, Firefox 19.0.2, and Safari 6.0.3 at least, if you have multiple elements with the same ID, jquery selectors (at least) will return the first element with that ID.
e.g.
and
See http://jsfiddle.net/RuysX/ for a test.
I think you can't do it because Id is unique you have to use it for one element . You can use class for the purpose