Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Quick question about self closing tags.

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default Quick question about self closing tags.

    Ok, this should be relatively straight forward, but I was under the impression that self closing tags were either ended like this: <br>, or <br/> (depending on doctype) but I keep coming across: <br /> with a space before the slash, is there any particular reason for this?

    Or is it just a way to make it more legible, it just seems rather arbitrary to me. I've only come across it since learning PHP, so is it specific to that, or what?

    Any help appreciated,

    Jack.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    It is needed for compatability with old browsers and to separate it from the last attribute's value (incase there are attributes).

    For further reading:
    http://www.westciv.com/style_master/...tml/index.html
    http://www.dynamicdrive.com/forums/s...ead.php?t=7934

    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Oh I see, thanks for that

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <foo /> is XML (and thus XHTML), and is equivalent to <foo></foo>. SGML (and thus HTML) is smarter, and allows definitions of empty tags in the DTD, such that this isn't necessary and an empty tag is considered to be closed as soon as it's opened; thus, <foo> is perfectly valid. <foo />, on the other hand, is equivalent to <foo>&lt; in SGML-compliant parsers, one of the reasons that XHTML cannot be safely served as text/html.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    I've seen some codes that have self closing div tags: <div />, usually with an id value. Is that really valid and what is the difference?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, it is entirely valid. As I said above, <div /> is, in XML/XHTML, entirely equivalent to <div></div>.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Ok, so can any content be added to this container or does that have to made through css?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's exactly equivalent to <div></div>. You can do anything to it that you can do with any other empty <div>.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Could this be done with other tags that are usually empty? E.g. <script type="text/javascript" src="jquery-1.2.6.min.js" />
    Would that work?

  10. #10
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Quote Originally Posted by Snookerman View Post
    Could this be done with other tags that are usually empty? E.g. <script type="text/javascript" src="jquery-1.2.6.min.js" />
    Would that work?
    Doing so will work on FF, but will break on IE (I've encountered that).

    You might find this thread useful too:
    http://www.webmasterworld.com/html/3614746.htm
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •