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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    To /> or not to />

    I can't figure out what to do with a difficult form of <table>. As we know, the simple case usually like this:

    <table><tr><td>
    Stuff
    </td></tr></table>

    BUT!

    It there are, say, formatting stuff included, one may, or may not, have to do something like this:

    <table style="whatever" /><tr><td>

    It seems that you can't close the <table with just the > as way above, but need to put in />, or is that only because quotes have been used?

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,269
    Thanks
    10
    Thanked 277 Times in 276 Posts
    You'd have to give an actual piece of code that shows your point that you need that slash. It is not needed or appropriate here:
    <table style="whatever" />
    ...regardless of whether you have a style clause.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,678
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    That code is invalid. A table (as many other elements) can only be closed with the according closing tag, that is </table>. But putting attributes in an opening tag has no relevance for the status of the element.

    Elements without attributes:
    Code:
    <div></div>
    <ul>
      …
    </ul>
    <table>
      …
    </table>
    The same elements with attributes:
    Code:
    <div style="…"></div>
    <ul style="…">
      …
    </ul>
    <table style="…">
      …
    </table>
    There are elements that, simply spoken, don’t have a closing tag by nature, such as <img>, <meta>, <input>. When HTML (version 4) was reformulated as application of XML (i. e. XHTML) such single elements needed to be closed, too (i. e. technically it would have been <img></img>), and there is a shortcut writing which is to put the closing slash right in the opening tag (<img/>).

    So, if you were writing XHTML you could close a table by writing <table/> (or, with attributes: <table style="…"/>) but that would mean you couldn’t put anything inside as the code you wrote as example would translate to:
    Code:
    <table style="whatever"></table>
    <tr>
    <td>
    which obviously is invalid.

    So, that said: Unless you are writing XHTML (either XHTML 4 or 5) you don’t need these closing slashes for single-tag elements at all.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You can't use XHTML until after IE8 finally dies as that browser doesn't support it. Until then you'd have to treat your XHTML as slightly invalid HTML.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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