PDA

View Full Version : What is the difference between id and class?



moin11
02-06-2012, 11:04 AM
I want to know that What is the difference between id and class? and How do I assign multiple classes to an element?

dikertrome
04-28-2012, 02:13 PM
I would like to share some of difference between ID and Class. ID means is short for fragment identifier, is a beautiful attribute, but it is very easy to use them poorly. You can only use an ID name once in any XHTML or HTML document. Classes means like ID's, can also be used to in JavaScript scripts, but unlike ID's, they can be used several times in the same HTML document.

johnnyS
05-08-2012, 02:38 PM
ID is an unique identifier of a specific HTML element, that's why it must be used once.

class is an identifier of an element that sets it as a member of one or more group.

To assign classes into an element, you will just separate them with a space.


<div id="my_id" class="class1 class2 class3"></div>

seo4js
05-14-2012, 11:52 AM
johnnyS is absolutely right. Plus you can also search on Google, there are tons of information there.

ronniemilsont
05-21-2012, 06:41 PM
These both are using in style file if you use id attribute in any html tag than you must use #attribute in style file. And if you use class in html tag than you must use .attribute in front of your style file.

prgetxhtml
05-25-2012, 11:07 AM
A Class definition can be used several times throughout your document, while an ID can only be used once. In CSS, class names are prepended with "a" and ID's are prepended with a '#'