SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The best way only out of these to comment

    Fully aware that there's other, probably better ways to code comments, but if you could only choose just one out of the 4 below, which one would be more correct than the others please ?

    <!-- This One !-->

    <!-- This One -->

    <!-- This One --!>

    <--! This One !-->

    Dez.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    <!-- This is an HTML comment as defined by the standard -->
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks, the quick input's appreciated. Do you, or anyone else know, if a comment such as that <!-- This One --> would have a detrimental effect on an onclick="document.getElementById please ?

    Dez.

  4. #4
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dez View Post
    <!-- This One -->
    Only really ever used this one. Didn't know the other were possible.

    I don't really know what you mean in your follow up question.

  5. #5
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks Tryst.

    In the follow up - I can't give an example url at the moment, but I remember a few months ago, that when the comments code was higher up on the page, and the onclick code lower down, the onclick 'focus' didn't work properly. Just wondered if others here have come across a similar thing with them.

    Dez.

  6. #6
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No sorry.

    But come back with an example when possible and we can look then.

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!--This is a comment-->

    #1 is valid, and I can see why some might prefer it because of the symmetry.

    #2 is the normal way to write a comment.

    #3 is odd, because the final exclamation point is outside the comment (the comment is terminated by the second pair of dashes). It might even be invalid.

    #4 is wrong. It's not an SGML or XML comment.
    Birnam wood is come to Dunsinane

  8. #8
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    I'm a fan of commenting code, and out of the three, #2 is what I use, though I'm trying to get away from commenting my HTML documents because IE6 doesn't always play nice in that regard.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  9. #9
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    <!--This is a comment-->

    #1 is valid, and I can see why some might prefer it because of the symmetry.

    #2 is the normal way to write a comment.

    #3 is odd, because the final exclamation point is outside the comment (the comment is terminated by the second pair of dashes). It might even be invalid.

    #4 is wrong. It's not an SGML or XML comment.
    Many thanks for the detailed response - I'll stick with number 2.

  10. #10
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kohoutek View Post
    I'm a fan of commenting code, and out of the three, #2 is what I use, though I'm trying to get away from commenting my HTML documents because IE6 doesn't always play nice in that regard.
    Many thanks for the input. One thing, in what way didn't IE6 play ball ? Was you using forms on the page ?

  11. #11
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    No, it didn't have anything to do with forms, at least not in my case. I simply had (probably too many) comments in my HTML and noticed that IE6 reacted with rendering issues. After removing a few comments, everything was fine again.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  12. #12
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kohoutek View Post
    No, it didn't have anything to do with forms, at least not in my case. I simply had (probably too many) comments in my HTML and noticed that IE6 reacted with rendering issues. After removing a few comments, everything was fine again.
    Many thanks for the confirmation. Has anyone found a way to solve that at all (without removing the comments) ? Wondering if formatting the comments like number 1 above would help ?

  13. #13
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kohoutek View Post
    No, it didn't have anything to do with forms, at least not in my case. I simply had (probably too many) comments in my HTML and noticed that IE6 reacted with rendering issues. After removing a few comments, everything was fine again.
    Two or more comments sandwiched between float elements cause duplicate characters to be rendered below the last float. Since form controls are often floated, it's a common problem there.

    Comments are not the only trigger. Apparently any non-rendered element can be the trigger; for instance, hidden input form controls, or display: none elements.

    Quote Originally Posted by Dez View Post
    Many thanks for the confirmation. Has anyone found a way to solve that at all (without removing the comments) ? Wondering if formatting the comments like number 1 above would help ?
    The fix for the doubled float margin bug also fixes the duplicate character bug. Simply make any float element display: inline. To my knowledge, there are no negative side effects.

    Another approach is to use MSFT conditional comments:
    <!--[if !ie]>comment here<![endif]-->

    IE7 fixed the bug.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  14. #14
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    That's absolutely correct, Gary. In my case, I had several floated elements and between those elements I had comments which caused the hiccups in IE6 and the last letter being duplicated.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  15. #15
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the extra info - much appreciated. This is what may have caused the problem before.

    Dez.

  16. #16
    SitePoint Wizard Blake Tallos's Avatar
    Join Date
    Jun 2008
    Location
    Cuyahoga Falls, Ohio.
    Posts
    1,511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code CSS:
    /* This is a comment */

    Code HTML4Strict:
    <!--This is a HTML Comment-->


    Code JavaScript:
    // Javascript
    Blake Tallos - Software Engineer for Sanctuary
    Software Studio, Inc. C# - Fanatic!
    http://www.sancsoft.com/


  17. #17
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by BlakeAnthony View Post
    Code CSS:
    /* This is a comment */

    Code HTML4Strict:
    <!--This is a HTML Comment-->


    Code JavaScript:
    // Javascript
    Many thanks, will bear that in mind as well.

  18. #18
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    #3 is odd, because the final exclamation point is outside the comment (the comment is terminated by the second pair of dashes). It might even be invalid.
    Yes it is invalid and some browsers close it while others don't (and in some it depends on whether there's a later "-->" or not).
    Simon Pieters

  19. #19
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    The code below is also a comment, if we want to follow the specification closely:
    Code html4strict:
    <!------ *** PAGE START *** -------->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     
    <html>
     <head>
      <title>Comment example</title>
     </head>
     <body>
      <h1>Comment example</h1>
      <p>This text is all a part of the comment.</p>
     </body>
    </html>
    <!-------- *** PAGE END *** ------>
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  20. #20
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not exactly true. Each pair of hyphens toggles the comment off or on.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  21. #21
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dez View Post
    Fully aware that there's other, probably better ways to code comments, but if you could only choose just one out of the 4 below, which one would be more correct than the others please ?

    <!-- This One !-->

    <!-- This One -->

    <!-- This One --!>

    <--! This One !-->

    Dez.
    I usually do something like this for indication of closing large sections of my document.
    <div class="section">
    </div>
    <!-- /section -->

    This way its easy to go back and troubleshoot

    3,4 are invalid ---

  22. #22
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gary.turner View Post
    Not exactly true. Each pair of hyphens toggles the comment off or on.

    cheers,

    gary
    Precisely. Count the hyphens. <!------ *** PAGE START *** --------> would break down as:
    • <!: Begin comment tag
    • ------: Begin comment (--), end comment (--) and begin comment (--)
    • *** PAGE START ***: Comment
    • --------: End comment (--), begin comment (--), end comment (--), begin comment (--)


    Everything following this (including the > immidiately following as well as the later <!) will be part of the comment, until the next time a double hyphen is encountered.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  23. #23
    SitePoint Wizard Blake Tallos's Avatar
    Join Date
    Jun 2008
    Location
    Cuyahoga Falls, Ohio.
    Posts
    1,511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cooper.semantics View Post
    I usually do something like this for indication of closing large sections of my document.
    <div class="section">
    </div>
    <!-- /section -->

    This way its easy to go back and troubleshoot

    3,4 are invalid ---
    Ohhh, for a large container you mean right? I had to go back and read that I was like wahhh? I understand now though.
    Blake Tallos - Software Engineer for Sanctuary
    Software Studio, Inc. C# - Fanatic!
    http://www.sancsoft.com/


  24. #24
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simon Pieters

  25. #25
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BlakeAnthony View Post
    Ohhh, for a large container you mean right? I had to go back and read that I was like wahhh? I understand now though.
    Sections of a document, or you could call them containers if you like
    <section>...</section><! --/section -->
    <section>...</section><!-- /section -->


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
  •