04-26-2004, 01:41 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.
04-26-2004, 02:07 AM
It is not valid (or is it well-formed?) to use the same ID for multiple elements - the ID serves to identify a singular element. Why not use classes instead?
Hope that helps!
Happy coding! :)
04-26-2004, 02:28 AM
yes I did make a mistake. What I did was
within my code I had the following
It took me 30 minutes to figure out that stupid mistake. I changed it to a class. Thanks for help.
03-11-2011, 09:29 PM
@the_matrix: please don't hijack very old threads. If you need help, start a new thread. Follow forum rules, use an appropriate title, show your work (use the # button in the editor to format code) and please respect the volunteers on this site.
If your current situation is similar to that of the original poster's (HTML validator is telling you that ID 'x' is already defined) - the easiest way to solve this is to change the ID to a CLASS. IDs must be unique in the document - you can only have one of each ID. CLASSes need not be unique - if you have many similar elements, they probably need a CLASS.
03-11-2011, 10:00 PM
thanks for the reply kansel. i appreciate everyone on here is a volunteer. i am not taking the mick in any way.
sorry dont mean to hijack but that is my exact problem
"ID "attachment_123" already defined"
i searched for the right thread and posted in this one as this was the best place. thats what we do on other forums.
my code is:
<div id="attachment_496" class="wp-caption alignright" style="width: 88px"><a tů
the W3C validator says:
An "id" is a unique identifier. Each time this attribute is used in a document it must have a different value. If you are using this attribute as a hook for style sheets it may be more appropriate to use classes (which group elements) than id (which are used to identify exactly one element).
any ideas please on how to change ID to a class?
03-11-2011, 10:25 PM
It looks like you may be using Wordpress (based on the wp-caption class name). If this is the case, your theme could be responsible for the validation error. The problem is that there is more than one instance of an element with the id="attachment_123" - this is not allowed.
Please post the complete HTML code (as seen in your browser's view source command) or post a link to the live page where we can see it in action.
03-11-2011, 10:48 PM
thanks for the reply.
my site is:
03-11-2011, 11:41 PM
You will need to get some help from someone who knows more about Wordpress. The attachment_187 that is causing the problem is the Hot Deal graphic on each post. This is probably being put together by a template in the theme and the template/theme file will have to be modified to correct the error.
The code will probably look something like this:
"<div id=\"attachment_" . attachID . "\" class=\"wp-caption alignright\">"
And will need to be changed to something more like this:
"<div class=\"wp-caption alignright attachment_" . attachID . "\">"
The basic idea is that you are moving the identifier attachment_187 (which could be a combination of a text string and variable) out of the ID attribute and into the CLASS attribute. Since the element already has two classes assigned, you will need to place the new identifier at the end of the other class names separated by a space.
Now this is NOT exactly what the code is going to look like - it will be something like that. You will need to consult someone who knows more about Wordpress template files either on this site or in the Wordpress developer community.
03-11-2011, 11:54 PM
thank you for your help. i truly appreciate it. mega karma from me to you.