Jump to content

Difference Between Id And Class

Difference between id and class

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Difference Between Id And Class Difference between id and class Rate Topic: -----

#1 User is offline   Joe Develper 

  • W.R. Corporal
  • Group: Members
  • Posts: 50
  • Joined: 07-December 10
  • Gender:Male
  • Interests:Web development, Internet Surfing etc.

Posted 09 December 2010 - 06:52 AM

Whats a difference between id and class? I am bit confused about it. :wacko:
0

#2 User is offline   Rob Kaper 

  • W.R. Corporal
  • Group: Members
  • Posts: 97
  • Joined: 19-July 08
  • Gender:Male
  • Location:Rotterdam, NLD

Posted 09 December 2010 - 06:57 AM

IDs are unique: no two elements can have the same ID (and no element can have more than one ID).

Classes can be reused: multiple elements can have the same class (and elements can have multiple classes at once).
Rob Kaper - Rotterdam
0

#3 User is offline   Joe Develper 

  • W.R. Corporal
  • Group: Members
  • Posts: 50
  • Joined: 07-December 10
  • Gender:Male
  • Interests:Web development, Internet Surfing etc.

Posted 10 December 2010 - 04:52 AM

hmm Thanks for your help, Rob.I appreciate it.
0

#4 User is offline   temhawk 

  • W.R. Private First-Class
  • Group: Members
  • Posts: 322
  • Joined: 30-August 07
  • Gender:Male
  • Interests:travel, cg art, macs, music, skateboarding, programming, discovery channel, TextMate 2

Posted 10 December 2010 - 06:29 PM

Also, you can use both an ID and a class (or multiple classes) on the same element, and the name of the ID can be the same as the class (or one of the classes).

The following is valid:

<div id="foo" class="foo bar">Lorem ipsum...</div>

(Note that "foo" and "bar" are two different classes, separated by a space.)

This post has been edited by temhawk: 10 December 2010 - 06:34 PM

0

#5 User is offline   Rob Kaper 

  • W.R. Corporal
  • Group: Members
  • Posts: 97
  • Joined: 19-July 08
  • Gender:Male
  • Location:Rotterdam, NLD

Posted 11 December 2010 - 01:05 AM

Note that if you use Ajax classes become increasingly less important now that browsers have better and faster support for CSS attribute selectors.

Because IDs need to be unique* you'll often end up with IDs such as comment_1 to avoid a collision with user 1, article 1 etcetera. You can still select all comments with the selector [id=^comment_] which selects all elements where the id attribute starts with comment_, effectively removing the need to also have a comment class. On elements you won't need to select uniquely classes are still preferred for performance.
Rob Kaper - Rotterdam
0

#6 User is offline   Joe Develper 

  • W.R. Corporal
  • Group: Members
  • Posts: 50
  • Joined: 07-December 10
  • Gender:Male
  • Interests:Web development, Internet Surfing etc.

Posted 12 December 2010 - 12:10 PM

I appreciate your help guys to understand this concept. Thanks once again.
0

#7 User is offline   denny 

  • W.R. Private
  • Group: Members
  • Posts: 29
  • Joined: 31-March 10

Posted 18 December 2010 - 12:48 AM

Thanks for clarifying between ID and Classes.I was bit confuse.
0

#8 User is offline   che09 

  • W.R. Corporal
  • Group: Members
  • Posts: 50
  • Joined: 22-November 10

Posted 19 December 2010 - 09:18 PM

ID's are unique

* Each element can have only one ID
* Each page can have only one element with that ID
ID's have special browser functionality
Here is one: your code will not pass validation if you use the same ID on more than one element. Validation should be important to all of us, so that alone is a big one.

Classes are NOT unique

Any styling information that needs to be applied to multiple objects on a page should be done with a class.


Both, Classes and ID's don't have any styling information to them all by themselves. They require CSS to target them and apply styling.
0

#9 User is offline   JakeMcGreg 

  • W.R. Private
  • Group: Members
  • Posts: 46
  • Joined: 15-December 10

Posted 13 February 2011 - 08:18 PM

Now I understand it better. Reading about ID stuff gives me more info. Thanks for elaborating on that one.
Website Design Packages - CMS Website, SEO Tools & a personalised 12 month strategy guide
0

#10 User is offline   EncoderDecoder 

  • W.R. Sergeant
  • Group: Members
  • Posts: 260
  • Joined: 01-March 11
  • Gender:Female
  • Location:Philippines

Posted 20 May 2011 - 11:07 AM

Quote

The key thing to know is that IDs identify a specific element and therefore must be unique on the page – you can only use a specific ID once per document. Many browsers do not enforce this rule but it is a basic rule of HTML/XHTML and should be observed. Classes mark elements as members of a group and can be used multiple times, so if you want to define a style which will be applied to multiple elements you should use a class instead.



- found this over the net.. ^_^
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users