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.
|