id and class. What´s the difference?

Discussion in 'HTML & Website Design' started by HDaddy, Mar 6, 2007.

  1. #1
    Could u guys and gals who have more experience tell me what is the difference
    in id and class. Sometimes i see in the code of sites lots of id="something" and sometimes there is only <div class="something". What´s the purpose of "id"?
    I tried to search for the explanation but couldn´t find one. So can u "draw me a picture" :) of what "id" does.

    thanks in advance.
     
    HDaddy, Mar 6, 2007 IP
  2. humanedited

    humanedited Peon

    Messages:
    747
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here's a quick and basic explanation:
    Div ID's are meant to be used only once on page
    ( <div id="contentshell">content here</div> )

    whereas "class" can be used multiple times on the same page.
     
    humanedited, Mar 6, 2007 IP
  3. resolva

    resolva Peon

    Messages:
    107
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Check out htmldog.com it will explain everything.

    I have pm'd you the exact link.
     
    resolva, Mar 6, 2007 IP
  4. usamzi

    usamzi Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The main difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.

    Both id and class are CSS properties and HTML attributes. They may be used to identify or classify a specific area of text, link, div, table etc.
     
    usamzi, Mar 6, 2007 IP
  5. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #5
    ID is used to identify an element in a page. It is similar to the name attribute. The problem with name is that, some elements can share the same name (like options of select box), whereas ID should be unique. ID is higly important as far as JavaScript is concerned. If you want javascript to access an element in your page, then ID is used.
    The main use of class attribute is to apply a CSS style to a group of element. You can declare a css class and have the same style applied to any number of elements by using the class attribute of the element. It is higly important as far as page designing is concerned.
     
    Aragorn, Mar 7, 2007 IP