Difference Between Id And Class
Difference between id and class
Page 1 of 1
Difference Between Id And Class Difference between id and class
#1
Posted 09 December 2010 - 06:52 AM
Whats a difference between id and class? I am bit confused about it.
#3
Posted 10 December 2010 - 04:52 AM
hmm Thanks for your help, Rob.I appreciate it.
#4
Posted 10 December 2010 - 06:29 PM
Also, you can use both an ID and a class (or multiple classes) on the same element, and the name of the ID can be the same as the class (or one of the classes).
The following is valid:
<div id="foo" class="foo bar">Lorem ipsum...</div>
(Note that "foo" and "bar" are two different classes, separated by a space.)
The following is valid:
<div id="foo" class="foo bar">Lorem ipsum...</div>
(Note that "foo" and "bar" are two different classes, separated by a space.)
This post has been edited by temhawk: 10 December 2010 - 06:34 PM
#5
Posted 11 December 2010 - 01:05 AM
Note that if you use Ajax classes become increasingly less important now that browsers have better and faster support for CSS attribute selectors.
Because IDs need to be unique* you'll often end up with IDs such as comment_1 to avoid a collision with user 1, article 1 etcetera. You can still select all comments with the selector [id=^comment_] which selects all elements where the id attribute starts with comment_, effectively removing the need to also have a comment class. On elements you won't need to select uniquely classes are still preferred for performance.
Because IDs need to be unique* you'll often end up with IDs such as comment_1 to avoid a collision with user 1, article 1 etcetera. You can still select all comments with the selector [id=^comment_] which selects all elements where the id attribute starts with comment_, effectively removing the need to also have a comment class. On elements you won't need to select uniquely classes are still preferred for performance.
Rob Kaper - Rotterdam
#6
Posted 12 December 2010 - 12:10 PM
I appreciate your help guys to understand this concept. Thanks once again.
#7
Posted 18 December 2010 - 12:48 AM
Thanks for clarifying between ID and Classes.I was bit confuse.
#8
Posted 19 December 2010 - 09:18 PM
ID's are unique
* Each element can have only one ID
* Each page can have only one element with that ID
ID's have special browser functionality
Here is one: your code will not pass validation if you use the same ID on more than one element. Validation should be important to all of us, so that alone is a big one.
Classes are NOT unique
Any styling information that needs to be applied to multiple objects on a page should be done with a class.
Both, Classes and ID's don't have any styling information to them all by themselves. They require CSS to target them and apply styling.
* Each element can have only one ID
* Each page can have only one element with that ID
ID's have special browser functionality
Here is one: your code will not pass validation if you use the same ID on more than one element. Validation should be important to all of us, so that alone is a big one.
Classes are NOT unique
Any styling information that needs to be applied to multiple objects on a page should be done with a class.
Both, Classes and ID's don't have any styling information to them all by themselves. They require CSS to target them and apply styling.
#9
Posted 13 February 2011 - 08:18 PM
Now I understand it better. Reading about ID stuff gives me more info. Thanks for elaborating on that one.
Website Design Packages - CMS Website, SEO Tools & a personalised 12 month strategy guide
#10
Posted 20 May 2011 - 11:07 AM
Quote
The key thing to know is that IDs identify a specific element and therefore must be unique on the page – you can only use a specific ID once per document. Many browsers do not enforce this rule but it is a basic rule of HTML/XHTML and should be observed. Classes mark elements as members of a group and can be used multiple times, so if you want to define a style which will be applied to multiple elements you should use a class instead.
- found this over the net..
Share this topic:
Page 1 of 1


Help
This topic is locked
MultiQuote










