![]() |
The Difference Between ID and Class
The Difference Between ID and Class
|
ID's
ID, short for fragment identifier, is a beautiful attribute, but it's very easy to use them improperly. You can only use an ID name once in any XHTML or HTML document. Classes Classes, like ID's, can also be used to in JavaScript scripts, but unlike ID's, they can be used multiple times in the same HTML document. |
Quote:
|
ID's are unique
Each element can have only one ID Each page can have only one element with that ID Classes are not unique We can use the same class on multiple elements. We can use multiple classes on the same element. |
ID:
Element can only one id,each page have only one element with id it is unique one. Class: It will be used for java script it will used multiple times in same html document. |
A lot of web designers new to the field aren't aware of the differences between ID's and classes. So here's a fairly brief article outlining proper and improper uses of the two.
|
In general, you can can create a class in a style sheet and add some styling code in it and you can use that class name to apply same type of styles to other objects in the UI like text or headings or paragraph without copying the code in the style sheet again.
|
ID:
id short for fragment identifier, is a beautiful attribute, but it's very easy to use them improperly. You can only use an ID name once in any XHTML or HTML document. Duplicate ID tags will cause your page to fail validation, and can have negative effects when using JavaScript with them. Classes: classes like ID's, can also be used to in JavaScript scripts, but unlike ID's, they can be used multiple times in the same HTML document. |
ID are Unique
Each element can have only one ID Each page can have only one element with that ID Class are Not Unique You can use the same class on multiple elements. You can use multiple classes on the same element. |
The ID selector is further specific than class, and the natural stream has been overridden. Class allocates you to prevent duplicating styles unnecessarily. You can also consist of several classes using only one attribute.
|
ID's
ID, short for fragment identifier, is a beautiful attribute, but it's very easy to use them improperly. You can only use an ID name once in any XHTML or HTML document. Classes Classes, like ID's, can also be used to in JavaScript scripts, but unlike ID's, they can be used multiple times in the same HTML document. __________________ |
id is use with # and class use with '.' .
|
ID's are unique
Each element can have only one ID Each page can have only one element with that ID Classes are NOT unique You can use the same class on multiple elements. You can use multiple classes on the same element. |
ID's are unique.Classes are not unique
|
All times are GMT -7. The time now is 09:46 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.