×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

How to write an HTML output in JavaScript?

Here, we are going to learn how to write a value on HTML i.e. as an HTML output in JavaScript?
Submitted by IncludeHelp, on February 02, 2019

When we are writing a JavaScript code and want to write on the HTML, we can use document.write() function, it accepts a simple string, variable, concatenated string, combinations of the multiple variables and print on the HTML document.

document.write()

Here, write() is an HTML DOM method and it writes the string/text to the HTML directly.

Syntax

document.write(string);
or
document.write(expression1, expression2, expression3, ...);

Example

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>		
		document.write("Hello world");
		document.write("<br>"); //HTML tag <br> for a new line
		document.write(10);
		document.write("<br>");
		document.write(10+20);
		document.write("<br>");		
		document.write("Hello", 10, "World");
		document.write("<br>");		
		document.write("Hello" + 10 + "World");
		document.write("<br>");		
		//writing including HTML tags
		document.write("Hello<br>world");
	</script>
</body>
</html>

Output

Hello world
10
30
Hello10World
Hello10World
Hello
world

JavaScript Tutorial »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.