Javascript

How to print text on page

The HTML <script> tag is used to insert a Java Script into an HTML page.

Example:1

How to write or print the text on a page.

<html>
 <body>
  <script type="text/javascript">
     <!--
     document.write("Paktutorial.com!")
      //-->
   </script>
 </body>
</html>

Output

Paktutorial.com!

Example 2

<html>
<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>My First Web Page</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

OUTPUT

My First Web Page

This is a paragraph.


Some Browsers do Not Support JavaScript

Browsers that do not support JavaScript, will display JavaScript as page content.

To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should be used to “hide” the JavaScript.

Just add an HTML comment tag <!– before the first JavaScript statement, and a –> (end of comment) after the last JavaScript statement, like this:

<script type="text/javascript">
<!--
   document.write("<h4>Vyom Technosoft!<h4>")
 //-->
</script>

The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This prevents JavaScript from executing the –> tag.

DOWNLOAD SOLUTION HERE