+ 3
What is the difference between ID and CLASS?
I was able to apply id and class multiple times on a single page. Then what is the actual difference between both?
13 Answers
+ 11
id should be used only once whereas class is for multiple use.
+ 10
class creates a style set, id targets a specific element. Many elements can have the same class but not the same id, well it can but it will crash any JavaScript code targeting it...
+ 4
i have noticed that when you want to access class you should add a dot in pfront of class name(.class) and id takes (#id) in then..id means identifying and class means mainly for styling porpose or section
+ 3
class is used to uniquely identify an element so that it (element) can be styled uniquely on CSS. Its mostly used for styling. (ie its associates an element with the style sheet)
Id is also a core attribute which also differentiates element that have the same name. It uniquely identifies an element within a HTML document
+ 3
It is convention not rule ,
that
"Class" selector is used for several elements , while "id" selector is used for only unique elements.
+ 2
id is for a specific element .
class is for various
+ 2
class can be used to identify many elements
id only one
+ 2
Usage needs would dictate which you wanted to use. Think of the difference More like a tool than a restriction. I'd is more surgical.
+ 2
Id and class are both attributes that a DOM element can have in a HTML document. The difference is that Id is an unique identifier, whereas the same class can be set to different elements. Any CSS set to a specific id will be applied to that element only and a css class can be shared by multiple elements. One important thing to notice is that Id has precedence over class, so any style property set for an Id will overwrite the CSS class, if it is set on the class level as well.
+ 1
Id is restrictive while class is liberal
+ 1
the major difference between Id and class I'd that, the I'd use can be use once in the per page but class can use many pages
+ 1
id always unique and can not be used twice while class can be use multiple times
+ 1
The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed