View Full Version : id x already defined

05-04-2011, 03:58 AM
I am trying to learn to be more rigorous with my XHTML and CSS code, and I am starting to validate everything that i do so that i learn the right way. One thing that a validator pointed out was that I had an ID that was already defined.

But my confusion is this. I have one style defined as #content #description and then another style defined as #restaurant #description.
Is that consider the same style? I looked at the explanation of the validator and it was more concerned about case-sensitivity than my issue, so it didn't really explain it. My guess is that that should be seen as two different styles. And if somebody can confirm that, then there must be something else wrong, and I can look elsewhere. Thanks for the info guys.
see this question in my site by wordpress www.freecalltrials.com

05-04-2011, 04:14 AM
Basically, to identify elements you can give them an id which must be unique on the web page or a class where multiple elements can have the same class.

If you have an element with say, id="myDiv" and you have another element on the same page, whether it is the same type of element or not is irrelevant, with id="myDiv" as well, then the w3c validator will be :mad: with you.

So, if you have multiple elements with the same id and you need those elements to have the same identifier values then you need to give them a class with the value set to the original id value.

In the css, you select an id with #myDiv and you select a class with .myDiv

I see your link now passes as XHTML Transitional so I assume your issue is resolved.

05-04-2011, 04:15 AM
You can't name two elements with the same id within your html:

<div id="myID"></div>
<p id="myID"></p>

You can have two elements with the same class though.