Hi ,
I am unable to use the newline character in javascript . My code is :
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello world \n Welcome to Javascript");
</script>
</body>
</html>
The output is : Hello world Welcome to Javascript.
Can anyone help ?
Newline character in Javascript
Moderator: General Moderators
-
littlecoder
- Forum Commoner
- Posts: 26
- Joined: Fri Oct 17, 2008 4:36 am
Re: Newline character in Javascript
Try the following
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello world <br> Welcome to Javascript");
</script>
</body>
</html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello world <br> Welcome to Javascript");
</script>
</body>
</html>
-
littlecoder
- Forum Commoner
- Posts: 26
- Joined: Fri Oct 17, 2008 4:36 am
Re: Newline character in Javascript
Hi ,
Thanks a lot.
It worked!!
Thanks a lot.
It worked!!
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Newline character in Javascript
The problem is not javascript. The problem is HTML. HTML does not recognize new lines. It only recognizes only line breaks (<br />, or <br>). Javascript is giving the new line, and it is there, but it isn't visualization is not initiated by the HTML engine.
Note: using the <pre></pre> tags enable you to use line breaks inside, along with extra spaces.
Note: using the <pre></pre> tags enable you to use line breaks inside, along with extra spaces.