/    Sign up×
Community /Pin to ProfileBookmark

Only one ID per page…..?

Hi!

I try to learn CSS, and in my book I read “You can only use an ID only once per page” What does that mean?

Does it mean that I can’t use an ID with the same name more than once? I must be able to use several ID for different parts on a site, as long as they don’t have the same name?

If I want to turn on and off eg the visibility for an element with javascript, then it must be an ID? Or isn’t javascript and CSS a good combination?

Looking forward for some guidelines in my effort to develop my skill! Thanks!

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@AugurioSJun 24.2009 — Hello...

Yes it means that you can only use an ID with the same name once per page, for it to be valid...
Copy linkTweet thisAlerts:
@Declan1991Jun 28.2009 — <div id="certain name"><p id="certain name"> is invalid because multiple elements have the same id. If you want to be able to reference multiple elements together, use the class attribute.
Copy linkTweet thisAlerts:
@WebWarriorJun 28.2009 — If I want to turn on and off eg the visibility for an element with javascript, then it must be an ID? Or isn't javascript and CSS a good combination?[/QUOTE]
If you want to turn on/off visibility for a particular element, then it must be an id. ID will uniquely identify that particular element. If you wanted to turn off multiple elements, you could give each one of them a CSS class (ex. class="turnOnOff") and then reference all elements with this class name through JavaScript. The later technique can be greatly simplified through the use of JQuery or you could use this Shawn Olson's Library (look for the changecss function). I would recommend going for JQuery, since it has a lot of facilities for creating dynamic CSS.
×

Success!

Help @pkng spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...