H I O X INDIA
Javascript Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch Portuguese Japanese தமிழ்
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
More about Javascript
Feedback



Javascript - write html tags, line break


Topic

How to insert a html code using javascript?
How to break the sequence of write method in javascript?



Explanation

HTML Code using Javascript:
HTML tags or code can also be added using document.write method.
i.e. Just use the html code as the argument for document.write or document.writeln functions
document.write("-- bold red --");

Example Code:
<script language=javascript>
document.write("-- <b>bold</b> <font color=red> red </font>--");
</script>


Result:


Break line for .write method :
document.write will append the string to the previous string.
i.e. if you call
document.write(" -- first line ---");
document.write(" -- second line ---");
the result will be as " -- first line --- -- second line ---";

So in order to break the lines in the browser you have to use an additional code "<br>" at the end.
e.g: document.write(" -- first line --- <br>");

Example Code:
<script language=javascript>
document.write(" -- first line --- <br>");
document.write(" -- second line --- <br>");
</script>


Result:


Test It:
Copy the code or type the code in to the text box shown below and click show.







        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

privacy policy     license     sitemap
© 2004-2010 HIOX INDIA

Other Links