+ 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?
4 Antworten
+ 16
I think class represents a group of tags, while an id is usually best suited to refer to a single tag
+ 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.
+ 2
thanks will check
+ 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 ^^