SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ID's and Classes... The difference is....?

    Hello,

    I just wanted to ask if there's any difference with ID's and Classes beside's a Class's functionality to work hierarchically with JavaScript.

    Are there any advantages IDs have over Classes that I don't know about? What's the official difference, if the Class's JS functionality isn't it?

    Thanks,

    GregC

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Simply put it is like this...

    ID's are for single elements. If you use the element or formatting once per page then an ID is useful... i.e.

    #header {formatting stuff here}
    #footer {formetting stuff here}

    Classes are useful when you need the same formatting on more than one element such as links or images.
    i.e.

    .headerlinks {formatting stuff here}
    .footerlinks {formatting stuff here}
    Wayne Luke
    ------------


  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In addition, IDs are very handy for using javascript to manipulate your pages via the DOM. If something has a unique ID you can access it by calling document.getElementByID('idtag') where idtag is the ID attribute of the element you wish to access.

  4. #4
    SitePoint Zealot ChrisOSX's Avatar
    Join Date
    May 2002
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W. Luke
    Simply put it is like this...

    ID's are for single elements. If you use the element or formatting once per page then an ID is useful... i.e.

    #header {formatting stuff here}
    #footer {formetting stuff here}

    Classes are useful when you need the same formatting on more than one element such as links or images.
    i.e.

    .headerlinks {formatting stuff here}
    .footerlinks {formatting stuff here}
    Wow! Is that really correct? I've been under the wrong assumption then. I thought that any ID defined in the page was an extension of the Body definition. In otherwords, my ID tags inherit all the attributes that I define in my Body tag, and can then extend them.


  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you assign an ID to a span tag and there is no formatting added to SPAN in the CSS, then it will inherit up through the body... This is why it is called Cascading.
    Wayne Luke
    ------------



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •