Jump to content

zeburrehman

Recommended Posts

An ID indicates that the element is unique and that there are no other elements on the page like it. A class indicates that an element has the same meaning as other elements of its same class name. You use ID to get one single element from the page, while you use class to get several of them.

Link to comment
Share on other sites

I'm not sure what there is to say that isn't well covered in the tutorials on w3schools. Id's are used to identify an element that will only appear once on a page. a class can be used for multiple elements.

 <html><head><style type="text/css"> #header{  width: 400px;  height: 400px;  margin: 0px auto;} .text{  color: black;  background-color: orange;}</style><body><div id="header">  <p class="text">Happy</p>  <p class="text">Halloween</p>  <p class="text">W3Schools Forums</p></div></body></html>

Link to comment
Share on other sites

What I don't get is why ID is relevant. I mean, class is basically the same as ID except it has more functionality. So really, why not just use class all the time? Does it eat up more space or something, is there any kind of advantage to using ID instead of class?

Link to comment
Share on other sites

In Javascript it's far easier to access en element by its ID than looking for one by its class name. In CSS, selectors with an ID in them have the highest priority.

Link to comment
Share on other sites

In Javascript it's far easier to access element by its ID than looking for one by its class name.
Ingolme is wright! Class and ID, have deferent meaning, hope you know that? If you want to understand them, then try reading about HTML class and id attributes.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...