Thread: Ending "/"

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

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    3

    Ending "/"


    What is the difference between

    <script src="example.js"></script>

    and

    <script src="example.js"/>

    what is the "/" for in the second example?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    Because proper syntax says all HTML tags must be closed.
    an improper tag would be
    Code:
    <script type="text/javascript" src="somejs.js">
    Where proper would be
    Code:
    <script type="text/javascript" src="somejs.js" />
    OR
    Code:
    <script type="text/javascript" src="somejs.js"></script>
    OR
    Code:
    <script type="text/javascript">
    SOME JS CODE
    </script>
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    HTML or XHTML?

    HTML doesn't support self-closing tags like that. Either the tag closes itself by definition and the slash means nothing or the tag contains content and the slash means nothing.
    So in fact
    Code:
    <script src="example.js"/>
    isn't viable.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    3
    thanks
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    A self-closing script tag is known to cause a bug in IE where content after the element is hidden.

    If you choose to use XHTML syntax, you should follow the HTML compatibility guidelines.

    The third guideline is this:
    Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).
    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