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 13 of 13
  1. #1
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why do we use " instead of ' ?

    First off, I've always used " as I believed it was the only option. Now I'm working with a C++ guy who uses ' instead. I told him it wouldn't validate, but it does?? (I didn't check his doctype however..)
    I did a little investigating at the good 'ol W3C and found although they accept both, ALL W3C examples are shown with ".
    In another thread, both Skyzyx and me' insisted that XHTML dictates the use of " for all attributes. Now I'm not doubting either of these guys as I've learnt a fair bit from both, but why???

    I'd really like to see some kind of official documentation or just reasoning that I'm not aware of 'cause this one's been floating round in my head for a week or two.

    I take no responsibility for the above nonsense.


    Left Justified

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    As long as you quote attributes (with ' or "), it really doesn't matter. De facto standard is ". " seems to make the values stand out for me anyway. But they're both equally valid, I'm pretty sure.

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, both are perfectly valid. However, I generally recommend using double-quotes in (X)HTML because that's how the majority of HTML code and documentation is written.

    Also, I tend to use single-quotes in JavaScript, and it helps me differentiate easily between the two.

    The most important thing is to be consistent and get a style going.

    The point that I was making in that other thread was that all attributes needed to be quoted in the first place. The guy I was trying to help hadn't quoted hardly anything at all, and was wondering about validation errors.
    Last edited by Skyzyx; 01-05-2004 at 05:23 AM.

  • #4
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Well, just my two cents, but when someone suggests quoting something, the first thing that comes into my head is "." So, I guess there's reasoning enough, structure attribute quotes in the same manner you would in everyday life.

    <<Unless, of course, you're from overseas and use another form of punctuation,>> I replied.

    -Rich

  • #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
    Originally posted by rmedek
    <<Unless, of course, you're from overseas and use another form of punctuation,>> I replied.
    Good point, but we have ways of getting round this.

    I didn't realise you could quote attribute values with ' myself, so I popped over to the w3c and had a look. After a few minutes of searching (jeez, you gotta hate the XML spec), I found it:
    The Name in the start- and end-tags gives the element's type. [Definition: The Name-AttValue pairs are referred to as the attribute specifications of the element], [Definition: with the Name in each pair referred to as the attribute name] and [Definition: the content of the AttValue (the text between the ' or " delimiters) as the attribute value.]Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.
    [quote source]]

    Well, there you go. I've never thought of using ", and I don't think this'll change things, but if you feel more comfortable this way, why not!?

    *goes back and edits other thread*
    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
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tend to prefer using the double quotes, unless i'm outputting the code via PHP, and i'm too lazy to go round espacing all my double quotes...
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Readme, you're supposed to use double quotes for strings really. Seeing as PHP is a C scripting language and in C 'a' would be 96 ( I think ) and "a" would be a ... It's just wrong in my oppinion to use ' for strings greater than 1 character in length ..
    Omnis mico antequam dominus Spookster!

  • #8
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by me'
    Good point, but we have ways of getting round this.
    Thanks for that one me'.

    I take no responsibility for the above nonsense.


    Left Justified

  • #9
    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 mindlessLemming
    Thanks for that one me'.
    I should point out that the support for :lang is extremely poor, so I'd use:
    Code:
    html[xml:lang|="fr"] span.example { quotes: "«" "»" }
    where the support is slightly better (moz, op off the top of my head)
    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!

  • #10
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    the " vs. the ' '

    I do know in the C++ language that the double quotes are used for strings and the signle quotes are used for a character for instance it would be a good thing to use for a menu. I do not know if that is one of the answers you are looking for, or I might have hit it way way off...
    thanks
    bri

  • #11
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The C or PERL (and later scripting languages using the same idea, such as Ruby, PHP etc.) difference between single and double quotes does not in any way affect SGML, XML or HTML. Neither of these do any differentiation between them. In fact, SGML is really lax and allows the language to specify other quoting characters if you want them.

    However, there are some rather good reasons for why you should use double instead of single quotes:
    - English language as well as many other languages uses single quotes (or apostrophes really, but ASCII doesn't differentiate those two characters) in regular writing, which means that you can't enclose such writing in single quotes without prematurely closing the string. Since SGML/HTML/XML character escaping is rather wieldy, you may want to avoid it altogether, by using a character not present in regular writing for string delimiter.
    - JavaScript may also use either single or double quotes for strings, but unlike SGML/HTML/XML character escaping, the JavaScript character escaping is small and makes the raw string only marginally less readable, which is the reason JavaScript traditionally uses single quotes. If we use double quotes for SGML/HTML/XML strings, that makes enclosing a single quoted JavaScript string in for example event handlers that much easier.
    - XML makes quoting strings necessary, but HTML is laxer and doesn't need it unless the attribute contains a space (parsers ignore that it should only be numbers that are allowed to be unquoted, really). As a preparation for XML and because it makes the code look nicer, you should use some quoting character for HTML strings even for numbers.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #12
    New Coder
    Join Date
    Dec 2003
    Location
    Central California
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, single and double quotes are interchangeable.

    But it will probably become more clear as to why when working with JavaScript.

    Example:

    Code:
    onclick = "document.location('http://www.google.com')";
    Here I could've started with the single quotes, but the inner quotes would've been double. And vice versa!
    /hector/rooted/@/a/puter

  • #13
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok I think this thread has achieved it purpose (possibly several posts back) and the same thing has been essentially said by a whole bunch of different people time to close this all you can post buffet.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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