Link to home
Start Free TrialLog in
Avatar of jean ala
jean alaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

document.write vs document.writeln

Hi
I can't see any difference between document.write and document.writeln. I searched the internet and found the followng example if I use the <pre> it works fine if I remove the <pre> it does not work. so what is this <pre>
Why write and writeln does not work without it?
What pre is used for?
Thanks

<html>
<body>

<pre>
<script type="text/javascript">
document.write("line1");
document.writeln("line2");
document.write("line3");
</script>
</pre>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of sjklein42
sjklein42
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jean ala

ASKER

Thanks for the reply
Everything was clear before the follwing statement:
>So you can either use "writeln" for all your output, or you need <pre>, or you need to insert <br> tags between each line.

The above statement was confusing
writeln alone as you confirmed (without <pre> will not work. Right?
<pre> alone will not insert a new line? correct

Even if you use writeln you will also need <pre>.  Your choice is between the use of a <pre> block plus writeln, vs the use of <br> tags between each line.  They're both pretty much the same but the choice may depends on whether you want fixed-width font (with <pre>) or variable.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks