Profile image of dvd-nis
Submitted by dvd-nis
almost 11 years

Using the same ID twice?

The text editor lets me use the exact same ID tag more than once and when I give specific attributes to that particular ID tag in the CSS file, all the elements with that one ID change. Doesn’t this make the functionality of ID exactly the same as the functionality of class?

Answer 536d27d8282ae358b60002b7

6 votes

Permalink

Profile image of LucienCooper
Submitted by LucienCooper
almost 11 years

7 comments

Profile image of dvd-nis
Submitted by dvd-nis
almost 11 years

Ahhh I see, mainly for javascript purposes. Thanks man

Profile image of mikechase3
Submitted by mikechase3
over 10 years

Thanks for asking this (and answering this). I was thinking the same thing myself.

Profile image of ddelph
Submitted by ddelph
over 10 years

Had the same question.Thanks for the answer

Profile image of amenthes
Submitted by amenthes
over 10 years

This is actually an error in the curriculum. You should not use “id” more than once. Usually, nothing will really break, but it’s bad practice.

Profile image of zystvan
Submitted by zystvan
about 10 years

@Lucien anybody posting a link to CSS Tricks gets an automatic upvote from me :)

Profile image of mavz
Submitted by mavz
almost 10 years

how do u add id in h1 for example

Profile image of zystvan
Submitted by zystvan
almost 10 years

@mavs: The same way you do for anything else: <h1 id="id">Text</h1>

Answer 536d6e77282ae3a786000309

3 votes

Permalink

For good measure, here is the CSS2 page for Selectors on w3.org.

Document languages may contain attributes that are declared to be of type ID. What makes attributes of type ID special is that no two such attributes can have the same value; whatever the document language, an ID attribute can be used to uniquely identify its element. … The ID attribute of a document language allows authors to assign an identifier to one element instance in the document tree. …

Profile image of mtf
Submitted by mtf
almost 11 years

Answer 54dd206086f5523c38000087

0 votes

Permalink

Using same ID more than once is a bad practice although it might work in many situations.

If you code the same in VB and try, it will throw a warning and automatically change the ID’s so that they are unique.

Profile image of bitPlayer50809
Submitted by bitPlayer50809
about 10 years

Answer 55c3302a937676139d00009e

-1 votes

Permalink

This exercise is wrong then, because it clearly asks from us to use the same ID twice (in french at least) and to apply CSS attributes only once. And when I do it works.

Profile image of redizdead
Submitted by redizdead
over 9 years