#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    102
    Rep Power
    7

    How to put quote within quotes in an HTML tag attribute?


    How can I do something like:

    <a href="this is a "test" for quotes">

    In most prog-languages you'd escape by a preceding backslash.

    BUT! I need to be able to use quotes outside and inside, I can not use singles inside doubles or vice versa.

    Any thoughts are appreciated.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    I'm curious, why can't you use single-quotes?

    The other solution is to use character entities:
    Code:
    <span title="this is a &quot;test&quot; for quotes">
    Last edited by Kravvitz; May 14th, 2008 at 01:15 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0
    I don't think Kravvitz's code came out quite right (the character entities were recognized as quotes ).

    Use & quot ; (remove the spaces between the &, quot, and ; ) in lieu of " such that it won't be recognized as the end quote of the href. It will still display as a quote in links or in text, though.

    Wikipedia has an article here .

    It's the same method you can view < and > in a browser without them being recognized as HTML tags....



    igfud
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    102
    Rep Power
    7
    Thank you both.

    I noticed that <a href="file with %22quotes% inside.html"> also works for file:

    file\ with\ \"quotes\"\ inside.html (a.k.a.: file with "quotes" inside.html)
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    You're welcome

    "%22" is a URL encoded character. As far as I know, it will only work where a URL is expected. (By the way, spaces in URLs must be URL encoded.)
    Originally Posted by x^2
    I don't think Kravvitz's code came out quite right (the character entities were recognized as quotes ).

    Use & quot ; (remove the spaces between the &, quot, and ; ) in lieu of " such that it won't be recognized as the end quote of the href. It will still display as a quote in links or in text, though.
    Thanks. I fixed it now.
    Last edited by Kravvitz; May 14th, 2008 at 01:19 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo