View Single Post
Old 2013-05-16, 01:34 PM   #24
Simon
That which does not kill us, will try, try again.
 
Simon's Avatar
 
Join Date: Aug 2003
Location: Conch Republic
Posts: 5,150
Send a message via ICQ to Simon Send a message via AIM to Simon Send a message via Yahoo to Simon
Yep, most browsers will let you get away with reusing IDs, at least right now. But if that ever changes in future browser versions you'll be very glad you changed those to classes.

--

You rarely need to use IDs instead of classes, except when you really want to indicate that some element on the page is actually unique.

For example, if an element has an ID of "submit_here" and you have a link that says "http://yourdomain.com#submit_here" then the browser will automatically scroll the page to find and show that section to whoever clicks the link.

The other reason to use an ID instead of a class is for Javascript. For example, if you're using the popular jQuery or similar Javascript libraries, then things like the "getElementById" function rely on there being only one element with the ID you specify.

Also, to go along with those things, while an element can have more than one class applied to it, an element can only have one ID.

Aside from those things, according to the "cascading" rules in CSS, an ID is chosen over a class if there are any conflicts in CSS declarations.

There may be other reasons to use an ID instead of a class, but those are the ones that first come to mind.

traffic is more important than design
__________________
"If you're happy and you know it, think again." -- Guru Pitka
Simon is offline   Reply With Quote