zeburrehman Posted October 28, 2011 Share Posted October 28, 2011 Hi everybody,Can some body please tell me the difference between Id and class not text wise but function wise. I have studied it every where but i didn't understand it. It's too complicated. Please explain it in simple words. I shall be really thankful to you.Regards Link to comment Share on other sites More sharing options...
Ingolme Posted October 28, 2011 Share Posted October 28, 2011 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 More sharing options...
eTianbun Posted October 28, 2011 Share Posted October 28, 2011 Class, is the group, which an element belongs to, while ID, is a unique name given to an element. Link to comment Share on other sites More sharing options...
thescientist Posted October 28, 2011 Share Posted October 28, 2011 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 More sharing options...
JustRob Posted October 28, 2011 Share Posted October 28, 2011 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 More sharing options...
Ingolme Posted October 29, 2011 Share Posted October 29, 2011 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 More sharing options...
eTianbun Posted October 29, 2011 Share Posted October 29, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.