+ 1

What is the difference between id and class ?

5th Apr 2017, 5:12 AM
Hacky AB
Hacky AB - avatar
2 Answers
+ 5
IDs are unique. only one element can have that ID(any given one). Classes, on the other hand, can be called as many time as you wish on as many element as you need.
5th Apr 2017, 5:19 AM
KINGDX - avatar
+ 1
IDs usualy used by javascript in order to find the exact element and edit it with javascript. Although it is possible to find an element by class using pure javascript or external libraries(like JQuery), finding an element by Id is much more faster so if you wana mark an element in order to edit it by some javascript codes Id is a better choice. On the other hand, Class is usualy used for styling the elements by a css file. As the others mentioned before Id should be unique in a page but you can have multiple elements with the same class or even an element with multiple classes in the same page.
5th Apr 2017, 5:30 AM
Mohammad Nej
Mohammad Nej - avatar