Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    id x already defined

    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.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

    #content .description
    #restaurant .description

    Hope that helps!

    Happy coding!

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes I did make a mistake. What I did was

    #content #description

    within my code I had the following
    Code:
    <div id="content">
       <div id="restaurant>
          <div id="description">...</div>
       </div>
       <div id="topic">
          <div id="description">...</div>
       </div>
    </div>
    It took me 30 minutes to figure out that stupid mistake. I changed it to a class. Thanks for help.

  • #4
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    same problem here.
    Last edited by the_matrix; 03-11-2011 at 09:51 PM.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    477
    Thanks
    0
    Thanked 51 Times in 50 Posts
    @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.

  • #6
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    477
    Thanks
    0
    Thanked 51 Times in 50 Posts
    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.

  • #8
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the reply.

    my site is:
    http://www.tandooricookingexpert.com/

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    477
    Thanks
    0
    Thanked 51 Times in 50 Posts
    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:
    Code:
    "<div id=\"attachment_" . attachID . "\" class=\"wp-caption alignright\">"
    And will need to be changed to something more like this:
    Code:
    "<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.

  • #10
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for your help. i truly appreciate it. mega karma from me to you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •