SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forward slash inside div - validator says "end tag for element X which is not open"

    I have a table which was showing up messed up in Firefox, so I checked the HTML in the validator. I found an odd error which can be boiled down to:
    Code:
    <img src="path" />
    <div class="name">Test/Text</div>
    The forward slash inside "Test/Text" creates an "end tag for element X which is not open" error message.

    I'm using htmlspecialchars() and that doesn't escape forward slashes - I was unaware they could cause issues. Is this error something I should be concerned with?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A forward slash there is completely valid and so isn't what the validator is complaining about. Can you post a link to the page so that we can see a bit more of the actual HTML.
    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
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to be either weird but correct SGML behavior or a bug in the validator.

    The slash in the img tag is a weird SGML "feature", where
    Code:
    <span/hello world/
    is equivalent to
    Code:
    <span>hello world</span>
    However, the img tag doesn't have an end tag, so "<img/>" is just equivalent to
    Code:
    <img>>
    But it seems the validator is still looking for a slash and interprets the slash in "Test/Text" as the end tag for the div.

    Possible solutions: remove the slash in the img tag; or change the doctype to an XHTML doctype or the HTML5 doctype. Or ignore it and use another validator without the silly SGML feature, like http://validator.nu/
    Simon Pieters

  4. #4
    SitePoint Zealot seoindiauk's Avatar
    Join Date
    Aug 2009
    Location
    New Delhi, India
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by Kadence View Post
    I have a table which was showing up messed up in Firefox, so I checked the HTML in the validator. I found an odd error which can be boiled down to:
    Code:
    <img src="path" />
    <div class="name">Test/Text</div>
    The forward slash inside "Test/Text" creates an "end tag for element X which is not open" error message.

    I'm using htmlspecialchars() and that doesn't escape forward slashes - I was unaware they could cause issues. Is this error something I should be concerned with?
    We know its ok, but HTML in the W3c validator will show error for that. Solution remove / i.e. do <img src="path"> instead of <img src="path" /> problem will be solved.

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zcorpan View Post
    It seems to be either weird but correct SGML behavior or a bug in the validator.

    The slash in the img tag is a weird SGML "feature", where
    Code:
    <span/hello world/
    is equivalent to
    Code:
    <span>hello world</span>
    However, the img tag doesn't have an end tag, so "<img/>" is just equivalent to
    Code:
    <img>>
    But it seems the validator is still looking for a slash and interprets the slash in "Test/Text" as the end tag for the div.
    Hmm, scrap the above, my testing was wrong. If the validator parses with a DTD it shouldn't give an error.
    Simon Pieters

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The slash in the img tag is invalid for HTML and shouldn't be there - it is required for XHTML though.
    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="^$">

  7. #7
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The slash in the img tag is invalid for HTML and shouldn't be there - it is required for XHTML though.
    Yes you're right - like zcorpan said it doesn't give the error the DTD passed and set as XHTML.


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
  •