Click to See Complete Forum and Search --> : Only one ID per page.....?


pkng
06-24-2009, 02:57 PM
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!

AugurioS
06-24-2009, 03:40 PM
Hello...

Yes it means that you can only use an ID with the same name once per page, for it to be valid...

Declan1991
06-28-2009, 01:40 PM
<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.

WebWarrior
06-28-2009, 02:19 PM
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?
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 (http://jquery.com/) or you could use this Shawn Olson's Library (http://www.shawnolson.net/scripts/public_smo_scripts.js) (look for the changecss function). I would recommend going for JQuery, since it has a lot of facilities for creating dynamic CSS.