Navbar

Saturday 22 June 2019

Ways to display output in JavaScript

Different way to display output in JavaScript

If you want to learn how many ways we can display our JavaScript output in web browser then read this article or watch the below mentioned video.

JavaScript can display your source code output by following ways : 
  1. Writing into an HTML element, using innerHTML
  2. Writing into the HTML output, using document.write()
  3. Writing into alert box using, using window.alert()
  4. Writing into the browser console, using console.log()

1. Using innerHTML : 

<html>
    <body>
       <p>My First Paragraph in innerHTML</p>
       <p id="mypara"></p>

       <script>
                 document.getElementById("mypara").innerHTML = "Hello JavaScript";
       </script>

    </body>
</html>

Explanation : As you can see we can display our data on browser first we defined the <p id="mypara"></p> and then print Hello JavaScript by using document.getElementById("mypara").innerHTML = "Hello JavaScript"; 

So this way you can display your desired output to the broswer by getElementById.



2. Using document.write(): 

<html>
    <body>
       <p>My First Paragraph in innerHTML</p>

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

    </body>
</html>

Explanation : You can print your desired output on web browser by using document.write() also.


3. Using window.alert(): 

<html>
    <body>
       <p>My First Paragraph in innerHTML</p>

       <script>
                 window.alert("Hello JavaScript");
       </script>

    </body>
</html>

Explanation : You can print your desired output on web browser by using window.alert() also.


Watch Video related to this topic [HINDI] click on play button


No comments:

Post a Comment

Share your views after read this post