views:

26

answers:

1

What is the rule behind to divide this html in var tip?

    var tip = "<p class='adobe-reader-download'>Most computers 
    will open PDF documents automatically, but you may need to download 
    <a title='Link to Adobe website-opens in a new window'";
    tip += " href='http://www.adobe.com/products/acrobat/readstep2.html'
 target='_blank'>Adobe Reader</a>.
    </p>";

why this cannot be

    var tip = "<p class='adobe-reader-download'>Most computers will 
    open PDF documents automatically, but you may need to download 
    <a title='Link to Adobe website-opens in a new window' 
href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>
    Adobe Reader</a>.</p>";

and how to divide in HTML is longer than this?

+1  A: 

You have to put a \ at the end of the line to tell Javascript the string spans onto the next line.

var tip = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb \
ccccccccccccccccccccccccccccccccccccccccccc";

It's not done very often though... you might find the following more readable:

var tip = "<p class='adobe-reader-download'>";

tip += "Most computers will open PDF documents automatically, ";
tip += "but you may need to download ";
tip += "<a title='Link to Adobe website-opens in a new window' ";
tip += "href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>";
tip += "Adobe Reader</a>.</p>";

etc.

Matt
is there any tool which can convert any `HTML` code into this `Var tip` format?
metal-gear-solid
What is the difference between `document.write` and `var tip`?
metal-gear-solid
Not that I know of. `document.write` will parse the string as HTML and write the result to the page (if `document.write` is called after the document has loaded, it will replace the current contents), however `var` simply creates a Javascript variable, which is a string (note, string, not DOM element).
Matt