SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    What's better: "element.class" or ".class"?

    From my understanding, ".class" is shorthand for "*.class"

    Does that slow things down at all, when I'm really only targeting a certain element? (The same goes for id's, especially. Is "#id" better, worse, or the same as "element#id"?)

    I'm particularly concerned about longer selectors. One looks faster, but the other seems like it would work faster:

    Code:
    #id .class element .class element {
        ...
    }
    element#id element.class element element.class element {
        ...
    }

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Those variants affect the specificity of the selector. Unless that makes a difference to whether or not it overrides some other selector it wouldn't make any noticeable difference and so the shorter one that allows the page to load a nanosecond or two faster would be the better option.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've sometime noticed that w/o element name, things are not going the desired way.

    and for speed performance, Never worked for large site, where it can be seen.


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
  •