JavaScript and new line..

Discussion in 'JavaScript' started by redhits, Oct 15, 2009.

  1. #1
    I need to insert lot of text in DIV.. the only problem is this:

    document.getElementById("submit").innerHTML="Preview"; is working just fine

    document.getElementById("submit").innerHTML="
    Text
    Preview
    text
    ";

    is not working... and i need to insert around 30 lines full of html code...
     
    redhits, Oct 15, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    var content = "line1<br />";
    content += "line2<br />";
    content += "line3<br />";
    ...
    
    document.getElementById("submit").innerHTML = content;
    PHP:
    you can't use whitespace in strings over new lines like you do in PHP.
     
    dimitar christoff, Oct 16, 2009 IP
  3. Gungz

    Gungz Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use the <br /> for breaking line in HTML.
    Because HTML won't parse \n to break the line.
     
    Gungz, Oct 22, 2009 IP
  4. ajaXpert

    ajaXpert Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    or simply like this:
    var content = 'Text<br>' +
    'Preview<br>' +
    'text<br>' +
     
    ajaXpert, Dec 4, 2009 IP