what is difference between id and class in html

0 votes
59 views
asked Oct 29, 2013 in HTML by Chanakya (545 points)
HI All

   what is difference between id and class in html

1 Answer

0 votes
answered Oct 29, 2013 by john (4,220 points)

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.

Javascript cares

JavaScript people are already probably more in tune with the differences between classes and ID's. JavaScript depends on there being only one page element with any particular, or else the commonly used getElementById function wouldn't be dependable.

 

...