Wow thanks for the great responses people! Love this list :)
Cheers, solved all my problems with that question :)
Paul Novitski wrote:
At 06:23 PM 1/12/05, Chris Stratford wrote:
I was asked for the first time yesterday, what the big difference and advantage to using an ID over a CLASS was...
Chris,
With regard to our intentions as scripters, what you and everyone else has said applies: ids are unique, classes are generic, and we should apply one or the other according to our understanding of the uniqueness of the object in the page structure.
At the same time, if I'm in an ambiguous situation in which I'm not sure whether to use id or class -- say because I've only got one instance of the object and I'm not sure whether there will ever be siblings -- I might choose id simply for reasons of speculative browser efficiency:
From a software mechanic's point of view, using id might be much faster than using class even if only one object is involved. [This difference in speed might or might not be too slim to be humanly perceptible.] I can easily imagine a browser resolving an id more quickly than a class. Within its memory structure there's likely just one position reserved for a given id, so that, when an id is referred to and the browser searches its internal index for a match, it will stop at the first match. In contrast, depending on how efficiently or inefficiently the browser has indexed objects by class, it may have to search the entire document object tree each time a classname is referenced to ensure that it catches all instances. Even if it's created a length-tagged array of objects with a given class, it's probably going to require a bit more processing to walk an array of even one member than it will have done to match a single unique id.
But pay no mind: this kind of thinking is very Old School. Why, way back in dem olden times, we had to pay attention to machine cycles because it really affected response time on a human scale. Nowadays everything runs so fast we can just focus on how to do things right and not worry about how long it takes the computer to do it.
Mmm, hmm!
Paul ****************************************************** The discussion list for http://webstandardsgroup.org/
See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help ******************************************************
-- ------------------------ Chris Stratford [EMAIL PROTECTED] http://www.neester.com ------------------------
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.11 - Release Date: 12/01/2005
****************************************************** The discussion list for http://webstandardsgroup.org/
See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help ******************************************************
