Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Very Simple Question! . vs #

    Ok This is a really simple question! I was wondering what is the difference between useing

    #Name

    or

    .Name

    In the scripts?



    Its been bugging me and I cant find any reference to it that I can see!

    Thanks

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In the scripts? I'm not sure about that, but in CSS you'd use "#" to signify an id, while you'd use a "." to signify a classname.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh so you use div id with # and div class with .

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Yeah ...


    Code:
    ...
    div#myDiv {
        color: orange;
        border: solid 2px black;
    }
    
    div.myDiv {
        color: blue;
        border: dashed 1px green;
    }
    ...
    
    <div id="myDiv">myDiv with id attribute</div>
    <div class="myDiv">myDiv with class attribute</div>
    That would return 2 completely different styled divs. A note also that the same id can only be used on 1 element per page whereas class can be used on as many as you want.
    Omnis mico antequam dominus Spookster!

  • #5
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And that ids are easier to work with once you get into the DOM, so use them when you can.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by me'
    And that ids are easier to work with once you get into the DOM, so use them when you can.
    Not really .. don't use an ID instead of a class just because you *might* want to identify that element in the DOM. If you *do* then add an ID, but otherwise classes are generally better for CSS because you'll have less code repetition, or smaller rules.

    Mind you, ID selectors have higher specificity than class selectors, which can be useful.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Unless of course you are working with invalid xhtml ..
    Omnis mico antequam dominus Spookster!

  • #8
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by brothercake
    but otherwise classes are generally better for CSS because you'll have less code repetition, or smaller rules.
    Oh yeah, of course, if you have a list of things that need to similary styled, use a class, but if you're referring to an individual element, there's normally absolutely nothing to say whether you should use classes or ids, so I'd use an id just because I might want to access it with the DOM.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!


  •  

    Posting Permissions

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