Document.Write() Method in JavaScript

JavaScriptIn JavaScript, Document.Write() method is used to write a string to the HTML document.  It takes a string as a parameter.  That string could be a plain text or a text in the form of HTML code.  Sample code for both scenarios is given below.

 

 

JavaScript Text:

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Tutorial </title>
</head>
<body>
<script type="text/javascript">
var message = "Hello World";
 
document.write(message);
 
</script>
 
</body>
</html>


HTML Code:

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Tutorial </title>
</head>
<body>
<script type="text/javascript">
 
document.write("<h1>Hello World!</h1>");
 
</script>
 
</body>
</html>

 

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •