View Full Version : 'ID already defined' Problems
assassingod
02-14-2004, 07:29 PM
Does anyone know why I cant use something like:
<div id="headerfont">Hello blah</div>
Here is some filler text
<div id="headerfont">hello again!</div>
moore
In XHTML? I get this error when validating:
ID "headerfont" already defined
This is very annoying because I need to use that id twice (and more times)
Anyway round it?
Dean C
02-14-2004, 08:17 PM
Have you checked in your CSS file that it hasn't been defined twice?
assassingod
02-14-2004, 08:28 PM
Yes. My CSS is completely valid.
Andreas
02-14-2004, 08:41 PM
IDs must be uniqe ... see W3C XHTML Documentation (http://www.w3.org/TR/xhtml1/#C_8)
The values of these attributes must be unique within the document,
If you use one ID more then once within a document you will run into problems when using JavaScript/DOM.
assassingod
02-14-2004, 08:48 PM
So what's a way round it? I need to use the ID twice.
Andreas
02-14-2004, 08:56 PM
You can't ;)
Why do you need this ID twice? For CSS?
assassingod
02-14-2004, 08:59 PM
Well I want to use the ID which is used by CSS for font title - and since there are many of them I want to use it more than once (unless im missing something?)
Andreas
02-14-2004, 09:23 PM
Well I want to use the ID which is used by CSS for font title
I don't understand that ...
Can you post an example of the CSS you want to apply/use?
Chroder
02-14-2004, 09:26 PM
I don't understand that ...
Can you post an example of the CSS you want to apply/use?
When you define CSS with a "#", you use it on an HTML tag with the ID attribute
#headerfont { color: red; }
<span id="headerfont">esfdsfds</span>
Andreas
02-14-2004, 09:31 PM
@Chroder
I do know how to apply CSS to IDs - thanks ;)
But I don't know what assassingod want's to achieve ...
#id CSS is for central formatting a single element (you could also just do that using style="..").
If he want's CSS for many element's he would use a class.
So I don't get why he needs multiple elements with the same ID, as this doesn't make sense to me?
assassingod
02-14-2004, 10:34 PM
Chroder said it fine, except I want to be able to use
<div id="headerfont">esfdsfds</div>
As many times as I want without getting that 'ID already defined' error.
Andreas
02-14-2004, 10:47 PM
This is not possible without breaking XHTML 1.0 rules :)
And I still don't understand WHY you need multiple elements with the same ID ...
<style type="text/css">
.headerfont {
font-family: Comic Sans MS;
color: red;
font-weight: bold;
}
</style>
[...]
<div class="headerfont">This is one text in bold, red, Comic Sans MS</div>
<div class="headerfont">And another one</div>
<div class="headerfont">A third one</div>
<div class="headerfont">A fourth one ... does this get boring? ;)</div>
assassingod
02-14-2004, 10:49 PM
Because i'll be implenting it into a system. So the output of the script will be:
<div class="whatever">
here is some text blah blach blah
<div>
And that code will be loop'd, so obviously there is going to be more than 1 result, ergo more div tags.
Andreas
02-14-2004, 10:53 PM
Well, in the code you just posted you are using class, so where is your ID problem?
Where do you need multiple elements with the same ID, that's what I don't understand?
assassingod
02-14-2004, 10:58 PM
Alright, let me try another way:)
Chroder
02-14-2004, 11:23 PM
@Chroder
I do know how to apply CSS to IDs - thanks ;)
But I don't know what assassingod want's to achieve ... lol Sorry ;) I thought you were confuzzled :nervous:
#id CSS is for central formatting a single element (you could also just do that using style=".."). I never knew that ;) I think I've been using ID's for multiple items as well.
* Chroder takes a note
assassingod
02-15-2004, 01:39 AM
Ok i've fixed it now - thanks:D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.