Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ID selector vs Class selector

Status
Not open for further replies.

Jaheel22

Technical User
Jul 14, 2004
84
US
Confused regarding the difference between ID selector and Class selector. Some body said that ID can be used only once on a page but Class can be used many times.
Would you please clarify it with some example ?
I use IDs on my pages and i can use the same ID many times like
<td id="abc">
<td id="abc">
etc.
Then why it is said ID can be used only once ?

Thanks very much.
 
ID can only be used once because it identifies a specific element. For example:
Code:
<td id="a12344"></td>
<td id="a12345"></td>
It's like giving a person a name. If you were in a group of people and two of the people had the same name, wouldn't you want to assign an alias of some sort to one of the two people to differentiate between them?

Classes group elements with common purposes together:
Code:
<td class="person"></td>
<td class="person"></td>
<td class="flower"></td>
That's not a very good example, but I'm sure you get the idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top