Embarrasingly simple document.write question (backslash and closing tags)

Discussion in 'JavaScript' started by Kerosene, Mar 7, 2010.

  1. #1
    Do I need to add a backslash when closing tags using document.write?
    It seems to work with or without.

    Which one is correct?

    document.write("<h1>Hello world</h1>This is my website<br />Goodbye");
    or
    document.write("<h1>Hello world<\/h1>This is my website<br \/>Goodbye");
    Code (markup):
     
    Kerosene, Mar 7, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You do not need the backslash to escape the normal slash as it is not a special character ;) You only need it to escape the usual meaning of a character e.g. if you would like to print a " you would nee the escape it with a backslash and write \" to print it
     
    Nyu, Mar 8, 2010 IP
    Kerosene likes this.