SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Brackets in id attributes

    Does anyone know if you can have brackets such as [] in your id?

    For example, <div id="test[5]"></div>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    Assuming they are used for attribute selectors I would say not.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that's not allowed. An id attribute must start with a letter (A-Z or a-z) and may be followed by zero or more letters, digits, periods, hyphens, underscores and colons.

    I wouldn't recommend using periods, since a period indicates a class selector in CSS. You'd then have to remember to escape the period in your selector (e.g., #foo\.bar). The CSS validator wouldn't mark it as an error if you forgot, since #foo.bar is a valid selector (matching an element whose ID is 'foo' and which belongs to the class 'bar').
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    excellent. Thank you for your responses.


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
  •