tags:

views:

51

answers:

6

Hello,

according to the HTML Standards ID-Attributes of any HTML Tag in a webpage have to be unique in the document!?

Does this rule also apply to HTML Tags that have been "disabled/hidden" by using: display:none?

Example:

<html>
<body>
<div id="one"></div>
<div id="one" style="display:none;"></div>
</body>
</hmtl>

Is this valid HTML or not. So the question is do "display:none"= hidden Elements also "count/matter" in regard to the rule only having unique ID-Attributes in a single webpage?

Thanks Jan

+6  A: 

It's not a valid markup. Validation does not take into account CSS styles applied to DOM elements.

There still has to be only one element per ID, regardless of whether it's visible or not, whether it is behind the others in the z-stack, whether it is positioned outside the viewport etc.

Developer Art
+1  A: 

Ids MUST be unique... to do otherwise is flirting with disaster!

Zoidberg
Poorly phrased! I feel like this could easily be misinterpreted... are you answering the first way he stated the question ("Does this rule also apply to HTML Tags that have been "disabled/hidden" by using: display:none?") or the second ("Is this valid HTML or not?") ?
LeguRi
Guess it wasn't a yes/no answerable question...
Zoidberg
A comment to request correction would have been enough mr. grumpy downvoter.
Zoidberg
+1  A: 

It doesn't matter if they are hidden or not they are still in the document. Even if they are created dynamically they shouldn't have the same ID. "it's not a valid markup" - Developer Art

c0mrade
A: 

Styling an element (even applying display:none) you do not remove the element from the document tree.

newtover
+1  A: 

Of course, as others have mentioned, it's not valid markup. You also have to think about DOM selection here. document.getElementById() selects one element with a particular ID, regardless of its visibility/display within the document.

Andy E
A: 

So the question is do "display:none"= hidden Elements also "count/matter" in regard to the rule

Yes. CSS doesn't affect whether a node is considered to be part of the document.

You can only have multiple Elements with the same ID when they're not both contained within the hierarchy of the same Document (or DocumentFragment), eg. when you've just used JavaScript to createElement a new node but not appendChild​ed it into the document yet.

bobince