+ 3

I am able to use both class & id multiple times on the same page and it works just fine. So, whats the difference between them?

10th Feb 2017, 7:45 AM
Gurpreet Singh
Gurpreet Singh - avatar
4 Respuestas
+ 16
I think class represents a group of tags, while an id is usually best suited to refer to a single tag
10th Feb 2017, 7:48 AM
Daniel Hisa (1,2,3, Let'sCode!)
Daniel Hisa (1,2,3, Let'sCode!) - avatar
+ 4
Both classes and id's are attributes to your html tags. So yes, technically you can use the same id multiple times throughout your pages. The standard convention however, is for an id to be unique to one tag and only be used once in a page/project. This helps to pinpoint a specific singular html element in your Javascript code and CSS if needed.
10th Feb 2017, 8:24 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
thanks will check
10th Feb 2017, 7:49 AM
Gurpreet Singh
Gurpreet Singh - avatar
+ 2
As already said, css targets multiple same id elements, but best practice is to avoid use of... as conceptual sense used elsewhere is that an id is unique, and could be source of bugs in some contexts ( particulary with JS and DOM interractions ). ... And behaviour of browsers about that can change in future ^^
10th Feb 2017, 10:58 AM
visph
visph - avatar