HTML DOM write() method


HTML DOM write() Method


Definition and usage


write() method can write to the document Enter HTML expression or JavaScript code.

Syntax

document.write(exp1,exp2,exp3,...)

Optional . The output stream to write to. Multiple parameters can be listed, and they will be appended to the document in the order they appear
ParametersDescription
##exp1,exp2,exp3,...


Browser support

QQ截图20161108165429.png

The write() method is supported by all major browsers


Example

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<script>
document.write("Hello World!");
</script>

</body>
</html>

Run instance»Click the "Run instance" button to view the online instance


Instance 2


## Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<script>
document.write("<h1>Hello World!</h1><p>Have a nice day!</p>");
</script>

</body>
</html>

Run instance»
Click the "Run instance" button to view the online instance



Instance 3


Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<p>注意write()方法不会在每个语句后面新增一行:</p>
<pre>
<script>
document.write("Hello World!");
document.write("Have a nice day!");
</script>
</pre>
<p>注意writeln()方法在每个语句后面新增一行:</p>
<pre>
<script>
document.writeln("Hello World!");
document.writeln("Have a nice day!");
</script>
</pre>

</body>
</html>

Running instance»
Click the "Run Instance" button to view the online instance